From c65efa32ac63a9bc752c4110770b717843610317 Mon Sep 17 00:00:00 2001 From: govin Date: Wed, 23 Sep 2026 13:06:12 +0800 Subject: [PATCH] frontend: indent the line a break starts, not just the paragraph's first MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit A Chinese manuscript indents the first line of every paragraph by two characters, and the paragraph body carried `text-indent: 2em` for it. CSS indents only the *first line of a block*, and the body was one block — so the opening line was indented and every line the writer broke (with 另起一行, or after a display formula) started flush against the margin, where a new paragraph should be indented. The bug was invisible until the break flag existed, because until then a paragraph had no interior line starts. The renderer now groups a paragraph into printed lines and makes each one its own block, with the indent on the line rather than on the paragraph: * the paragraph's first line — indented, as before; * a line the writer broke — indented, which is the fix; * a line after a display formula — **not** indented, because that text continues the same paragraph and a Chinese manuscript does not indent a continuation; * a display formula's own line — centred, no indent. Measured in the browser on a paper built for it: the first line starts 30px in (2em at 15px), the broken line starts 30px in, the formula sits on its own centred line, and the text after it returns to 0. Paper 96 is unchanged at 21 paragraphs, all 21 still indented 30px, 28 display formulas, no render failures. 54 paper checks, 61 reference checks and 99 MCP checks pass, with the build clean. --- docs/OVERVIEW.md | 9 ++ .../src/components/papers/PaperParagraph.vue | 137 +++++++++++++----- 2 files changed, 108 insertions(+), 38 deletions(-) diff --git a/docs/OVERVIEW.md b/docs/OVERVIEW.md index 3005ead..682b9a2 100644 --- a/docs/OVERVIEW.md +++ b/docs/OVERVIEW.md @@ -323,6 +323,15 @@ A break also **replaces** the separator rather than adding to it: the new line already separates the two sentences, and a space as well would indent the line by one blank. +The renderer groups a paragraph into *printed lines* to make that work. CSS can +only indent the first line of a block, so a paragraph printed as one block +indents its opening line and leaves every line the writer broke flush against +the margin — which is exactly where a new paragraph should be indented. So each +printed line is its own block, and the two-character first-line indent sits on +the line rather than on the paragraph. A line after a display formula is the +exception: that text continues the same paragraph, and a Chinese manuscript +does not indent a continuation. + #### What goes at the seam A paragraph is printed by concatenating its sentences in `sort` order, so the diff --git a/frontend/src/components/papers/PaperParagraph.vue b/frontend/src/components/papers/PaperParagraph.vue index 97d083d..7a0d02f 100644 --- a/frontend/src/components/papers/PaperParagraph.vue +++ b/frontend/src/components/papers/PaperParagraph.vue @@ -78,6 +78,51 @@ const rendered = computed(() => })), ) +/** + * One printed line: the sentences that share it, and whether it is indented. + * + * Grouping is needed because the two-character first-line indent of a Chinese + * manuscript is a property of a *line*, and CSS can only indent the first line + * of a block. Printing the whole paragraph as one block therefore indents its + * opening line and nothing else — which is right until the writer asks for a + * break, and then the new line starts flush against the margin where a new + * paragraph should be indented. + * + * A line starts when the writer breaks one, when a display formula needs a line + * of its own, or after one (a block always ends the line it sits in). + */ +interface RenderedLine { + /** Whether the first line of this block is indented by two characters. */ + indent: boolean + items: RenderedSentence[] +} + +const renderedLines = computed(() => { + const lines: RenderedLine[] = [] + + rendered.value.forEach((item, index) => { + const previous = rendered.value[index - 1] + const startsLine = + index === 0 || // the paragraph's own first line + item.lineBreak || // the writer asked for one + item.display || // a display formula takes a line of its own + Boolean(previous?.display) // …and the line after it starts fresh + + if (startsLine) { + lines.push({ + // Indented at the start of the paragraph, and after a break the writer + // asked for. Not after a display formula: that text continues the same + // paragraph, and a Chinese manuscript does not indent a continuation. + indent: index === 0 || item.lineBreak, + items: [], + }) + } + lines[lines.length - 1]!.items.push(item) + }) + + return lines +}) + /** Whether anything has actually been written here. */ const hasContent = computed(() => rendered.value.some( @@ -126,45 +171,49 @@ const anchor = computed(() => `paragraph-${props.paragraph.paper_template_filed_
- +