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:
@@ -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
|
already separates the two sentences, and a space as well would indent the line
|
||||||
by one blank.
|
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
|
#### What goes at the seam
|
||||||
|
|
||||||
A paragraph is printed by concatenating its sentences in `sort` order, so the
|
A paragraph is printed by concatenating its sentences in `sort` order, so the
|
||||||
|
|||||||
@@ -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. */
|
/** Whether anything has actually been written here. */
|
||||||
const hasContent = computed(() =>
|
const hasContent = computed(() =>
|
||||||
rendered.value.some(
|
rendered.value.some(
|
||||||
@@ -126,7 +171,13 @@ const anchor = computed(() => `paragraph-${props.paragraph.paper_template_filed_
|
|||||||
</header>
|
</header>
|
||||||
|
|
||||||
<div v-if="hasContent" class="paragraph-body">
|
<div v-if="hasContent" class="paragraph-body">
|
||||||
<template v-for="item in rendered" :key="item.sentence.id">
|
<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
|
<!-- A display formula is a block by definition, so it takes its own
|
||||||
line whether or not the writer asked for a break. -->
|
line whether or not the writer asked for a break. -->
|
||||||
<span
|
<span
|
||||||
@@ -134,10 +185,7 @@ const anchor = computed(() => `paragraph-${props.paragraph.paper_template_filed_
|
|||||||
class="sentence sentence--display"
|
class="sentence sentence--display"
|
||||||
v-html="item.html"
|
v-html="item.html"
|
||||||
></span>
|
></span>
|
||||||
<template v-else>
|
<span v-else class="sentence" v-html="item.html"></span>
|
||||||
<br v-if="item.lineBreak" />
|
|
||||||
<span class="sentence" v-html="item.html"></span>
|
|
||||||
</template>
|
|
||||||
|
|
||||||
<el-tooltip
|
<el-tooltip
|
||||||
v-for="citation in item.sentence.citations"
|
v-for="citation in item.sentence.citations"
|
||||||
@@ -165,6 +213,7 @@ const anchor = computed(() => `paragraph-${props.paragraph.paper_template_filed_
|
|||||||
<sup class="cite-mark">{{ citationIndex[citation.id] ?? '?' }}</sup>
|
<sup class="cite-mark">{{ citationIndex[citation.id] ?? '?' }}</sup>
|
||||||
</el-tooltip>
|
</el-tooltip>
|
||||||
</template>
|
</template>
|
||||||
|
</p>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- Nothing below the heading when there is nothing to print. An empty
|
<!-- 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;
|
line-height: 2;
|
||||||
color: var(--el-text-color-primary);
|
color: var(--el-text-color-primary);
|
||||||
text-align: justify;
|
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. */
|
/* The two-character indent a Chinese manuscript expects. */
|
||||||
text-indent: 2em;
|
text-indent: 2em;
|
||||||
overflow-wrap: anywhere;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.sentence {
|
.sentence {
|
||||||
|
|||||||
Reference in New Issue
Block a user