txt: trim punctuations in parsed author names (#1707)

* txt: trim punctuations in parsed author names

* release: version 0.9.68
This commit is contained in:
Huang Xin
2025-07-30 02:50:21 +08:00
committed by GitHub
parent c581f8ab47
commit aa3cd2a0c5
3 changed files with 17 additions and 7 deletions
+5 -1
View File
@@ -62,7 +62,11 @@ export class TxtToEpubConverter {
const authorMatch =
fileHeader.match(/[【\[]?作者[】\]]?[:\s]\s*(.+)\r?\n/) ||
fileHeader.match(/[【\[]?\s*(.+)\s+著\s*[】\]]?\r?\n/);
const author = authorMatch ? authorMatch[1]!.trim() : providedAuthor || '';
let matchedAuthor = authorMatch ? authorMatch[1]!.trim() : providedAuthor || '';
try {
matchedAuthor = matchedAuthor.replace(/^[\p{P}\p{S}]+|[\p{P}\p{S}]+$/gu, '');
} catch {}
const author = matchedAuthor || providedAuthor || '';
const language = providedLanguage || this.detectLanguage(fileHeader);
const identifier = await partialMD5(txtFile);
const metadata = { bookTitle, author, language, identifier };