frontend: indent the line a break starts, not just the paragraph's first

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.
This commit is contained in:
2026-09-23 13:06:12 +08:00
parent 9f2bbe50eb
commit c65efa32ac
2 changed files with 108 additions and 38 deletions
@@ -78,6 +78,51 @@ const rendered = computed<RenderedSentence[]>(() =>
})),
)
/**
* 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<RenderedLine[]>(() => {
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_
</header>
<div v-if="hasContent" class="paragraph-body">
<template v-for="item in rendered" :key="item.sentence.id">
<!-- A display formula is a block by definition, so it takes its own
line whether or not the writer asked for a break. -->
<span
v-if="item.display"
class="sentence sentence--display"
v-html="item.html"
></span>
<template v-else>
<br v-if="item.lineBreak" />
<span class="sentence" v-html="item.html"></span>
</template>
<p
v-for="(line, index) in renderedLines"
:key="index"
class="paragraph-line"
:class="{ 'is-indented': line.indent }"
>
<template v-for="item in line.items" :key="item.sentence.id">
<!-- A display formula is a block by definition, so it takes its own
line whether or not the writer asked for a break. -->
<span
v-if="item.display"
class="sentence sentence--display"
v-html="item.html"
></span>
<span v-else class="sentence" v-html="item.html"></span>
<el-tooltip
v-for="citation in item.sentence.citations"
:key="citation.id"
placement="top"
:show-after="120"
>
<template #content>
<div class="cite-tip">
<div class="cite-tip-head">[{{ citationIndex[citation.id] ?? '?' }}]</div>
<!-- What the number means: the entry as the bibliography prints
it, not its database id. -->
<div
v-if="citation.reference_id != null && referenceText[citation.reference_id]"
class="cite-tip-entry"
>
{{ referenceText[citation.reference_id] }}
<el-tooltip
v-for="citation in item.sentence.citations"
:key="citation.id"
placement="top"
:show-after="120"
>
<template #content>
<div class="cite-tip">
<div class="cite-tip-head">[{{ citationIndex[citation.id] ?? '?' }}]</div>
<!-- What the number means: the entry as the bibliography prints
it, not its database id. -->
<div
v-if="citation.reference_id != null && referenceText[citation.reference_id]"
class="cite-tip-entry"
>
{{ referenceText[citation.reference_id] }}
</div>
<div v-else class="cite-tip-unlinked">
这处引用还没有关联文献库条目
</div>
<div class="cite-tip-quote">「{{ citation.quote }}」</div>
</div>
<div v-else class="cite-tip-unlinked">
这处引用还没有关联文献库条目
</div>
<div class="cite-tip-quote">「{{ citation.quote }}」</div>
</div>
</template>
<sup class="cite-mark">{{ citationIndex[citation.id] ?? '?' }}</sup>
</el-tooltip>
</template>
</template>
<sup class="cite-mark">{{ citationIndex[citation.id] ?? '?' }}</sup>
</el-tooltip>
</template>
</p>
</div>
<!-- Nothing below the heading when there is nothing to print. An empty
@@ -250,9 +299,21 @@ const anchor = computed(() => `paragraph-${props.paragraph.paper_template_filed_
line-height: 2;
color: var(--el-text-color-primary);
text-align: justify;
overflow-wrap: anywhere;
}
/* One printed line. The indent lives here rather than on the body because CSS
indents only the first line of a block: a paragraph printed as a single block
would indent its opening line and leave every line the writer broke flush
against the margin. */
.paragraph-line {
margin: 0;
text-indent: 0;
}
.paragraph-line.is-indented {
/* The two-character indent a Chinese manuscript expects. */
text-indent: 2em;
overflow-wrap: anywhere;
}
.sentence {