forked from akai/readest
This commit is contained in:
@@ -133,9 +133,35 @@ export class TxtToEpubConverter {
|
||||
),
|
||||
);
|
||||
} else {
|
||||
chapterRegexps.push(
|
||||
/(?:^|\n|\s)(?:(Chapter|Part)\s+(\d+|[IVXLCDM]+)(?:[:.\-–—]?\s+[^\n]*)?|(?:Prologue|Epilogue|Introduction|Foreword)(?:[:.\-–—]?\s+[^\n]*)?)(?=\s|$)/gi,
|
||||
);
|
||||
const chapterKeywords = ['Chapter', 'Part', 'Section', 'Book', 'Volume', 'Act'];
|
||||
|
||||
const prefaceKeywords = [
|
||||
'Prologue',
|
||||
'Epilogue',
|
||||
'Introduction',
|
||||
'Foreword',
|
||||
'Preface',
|
||||
'Afterword',
|
||||
];
|
||||
|
||||
const numberPattern = String.raw`(\d+|[IVXLCDM]+)`;
|
||||
const dotNumberPattern = String.raw`\.\d{1,4}`;
|
||||
const titlePattern = String.raw`[^\n]{0,50}`;
|
||||
|
||||
const normalChapterPattern = chapterKeywords
|
||||
.map(
|
||||
(k) =>
|
||||
String.raw`${k}\s*(?:${numberPattern}|${dotNumberPattern})(?:[:.\-–—]?\s*${titlePattern})?`,
|
||||
)
|
||||
.join('|');
|
||||
|
||||
const prefacePattern = prefaceKeywords
|
||||
.map((k) => String.raw`${k}(?:[:.\-–—]?\s*${titlePattern})?`)
|
||||
.join('|');
|
||||
|
||||
const combinedPattern = String.raw`(?:^|\n|\s)(?:${normalChapterPattern}|${prefacePattern})(?=\s|$)`;
|
||||
|
||||
chapterRegexps.push(new RegExp(combinedPattern, 'gi'));
|
||||
}
|
||||
|
||||
const formatSegment = (segment: string): string => {
|
||||
|
||||
Reference in New Issue
Block a user