Implement WebGL page reserve navigation

This commit is contained in:
2026-06-08 10:25:54 +02:00
parent 3e28d7db23
commit efd1e6cfff
13 changed files with 571 additions and 52 deletions
+28 -2
View File
@@ -24,6 +24,7 @@ class MarkupParserModule extends BaseModule {
'parseImageOptions',
'parseSfxOptions',
'parseMusicOptions',
'parsePageReserveDirective',
'markdownToHtml',
'markdownToPlainText',
'smartypants',
@@ -178,11 +179,14 @@ class MarkupParserModule extends BaseModule {
}
parseParagraph(rawText) {
const inline = this.parseInline(this.normalizeParagraph(rawText));
const normalized = this.normalizeParagraph(rawText);
const reserveDirective = this.parsePageReserveDirective(normalized);
const inline = this.parseInline(reserveDirective.text);
return {
text: this.markdownToPlainText(inline.text),
layoutText: this.markdownToHtml(inline.text),
cueMarkers: inline.cueMarkers
cueMarkers: inline.cueMarkers,
pageReserve: reserveDirective.directive
};
}
@@ -193,12 +197,34 @@ class MarkupParserModule extends BaseModule {
layoutText: paragraph.layoutText,
cueMarkers: paragraph.cueMarkers,
role,
metadata: {
...(paragraph.pageReserve ? { pageReserve: paragraph.pageReserve } : {})
},
isFirstParagraphInChapter: role === 'chapter-first' || role === 'textblock-first',
dropCap: role === 'chapter-first',
addTopSpace: role === 'textblock-first'
};
}
parsePageReserveDirective(text) {
const source = String(text || '');
const match = source.match(/#pagereserve\[\s*([0-9]+(?:\.[0-9]+)?)\s*(%)?\s*\]/i);
if (!match) {
return { text: source, directive: null };
}
const value = Number(match[1]);
const directive = Number.isFinite(value)
? {
value,
unit: match[2] === '%' ? 'percent' : 'pages'
}
: null;
return {
text: source.replace(match[0], '').replace(/\s{2,}/g, ' ').trim(),
directive
};
}
parseInline(text) {
return {
text: String(text || '').replace(/\s{2,}/g, ' ').trim(),