fix: an index entry keeps the hard break its heading has

A book's chapter heading is "Chapter 1" and its title on two lines, and both
LibreOffice and Word copy that break into the index. We joined it into one line,
so a fixture's contents came out 18 rows short. The leader and page
number ride the last of an entry's lines (align-items: last baseline).
This commit is contained in:
Steffen Becker committed 2026-08-11 19:52:02 +00:00
1 parent 860e25d8c8
commit 3cf1d34035
3 files changed
+13 -4

No files matched your search

+9 -2
View File
@@ -156,7 +156,11 @@ class TocView {
const out: HeadingRef[] = [];
this.editor.state.doc.descendants((node, pos) => {
if (node.type.name === 'heading') {
const text = node.textContent.trim();
// A hard break inside the heading is a line of the entry too — a book's
// "Chapter 1" / title pair is two lines in LibreOffice's own index.
let raw = '';
node.forEach((child) => { raw += child.type.name === 'hardBreak' ? '\n' : child.textContent; });
const text = raw.trim();
const level = Math.min(MAX_HEADING_LEVEL, (node.attrs.level as number) ?? 1);
if (text && level <= max) out.push({ text, level, pos });
}
@@ -246,7 +250,10 @@ class TocView {
if (levelStyle) row.dataset.style = levelStyle;
const text = document.createElement('span');
text.className = 'toc-text';
text.textContent = e.text;
e.text.split('\n').forEach((part, li) => {
if (li) text.appendChild(document.createElement('br'));
text.appendChild(document.createTextNode(part));
});
const leader = document.createElement('span');
leader.className = 'toc-leader';
// Real fill characters, as a word processor draws them: they scale with the font
+1 -1
View File
@@ -3268,7 +3268,7 @@ function tocXml(toc: TocExport, index: number): string {
`</text:index-title>`
: '') +
toc.entries
.map(e => `<text:p text:style-name="${tocLevelStyle(toc, e.level)}">${escapeXml(e.text)}<text:tab/>${e.page}</text:p>`)
.map(e => `<text:p text:style-name="${tocLevelStyle(toc, e.level)}">${escapeXml(e.text).replace(/\n/g, '<text:line-break/>')}<text:tab/>${e.page}</text:p>`)
.join('') +
`</text:index-body>`;
return `<text:table-of-content text:name="${escapeXml(name)}" text:protected="true">${source}${body}</text:table-of-content>`;
+3 -1
View File
@@ -225,7 +225,9 @@
}
.paper .tiptap .toc-entry {
display: flex;
align-items: baseline;
/* The last one: an entry whose heading carries a hard break is several lines, and the
leader and page number belong beside the last of them. */
align-items: last baseline;
cursor: pointer;
}
.paper .tiptap .toc-entry:hover .toc-text {