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_
- +