Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions frontend/src/postBodyDisplay.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,28 @@ describe("splitPostBody", () => {
]);
});

it("preserves nested HTML list depth as semantic indentation", () => {
expect(
splitPostBody("<ol><li>Parent<ol><li>Child</li></ol></li><li>Sibling</li></ol>"),
).toEqual([
{ kind: "text", text: "Parent" },
{ kind: "text", text: "Child", indentLevel: 1 },
{ kind: "text", text: "Sibling" },
]);
});

it("preserves nested list depth when item text is wrapped in a block child", () => {
expect(
splitPostBody(
"<ol><li><p>Parent</p><ol><li><p>Child</p></li></ol></li><li><p>Sibling</p></li></ol>",
),
).toEqual([
{ kind: "text", text: "Parent" },
{ kind: "text", text: "Child", indentLevel: 1 },
{ kind: "text", text: "Sibling" },
]);
});

it("labels HTML, Word, and OOXML footnotes in the fallback renderer", () => {
expect(
splitPostBody(
Expand Down
13 changes: 11 additions & 2 deletions frontend/src/postBodyDisplay.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,11 +143,20 @@ function indentMarker(width: number): string {

function stripHtmlTags(text: string): string {
text = markFootnoteTags(text).replace(/<sup[^>]*>(.*?)<\/sup>/gi, "^$1");
let listDepth = 0;
const withBoundaries = text
.replace(BREAK_TAG, "\n")
.replace(BLOCK_TAG, (tag) => {
if (/^<\//.test(tag)) return "\n\n";
return `\n\n${indentMarker(declaredIndentWidth(tag))}`;
const name = tag.match(/^<\/?\s*([a-z0-9:]+)/i)?.[1]?.toLowerCase() ?? "";
const closing = /^<\//.test(tag);
if (name === "ul" || name === "ol") {
if (closing) listDepth = Math.max(0, listDepth - 1);
else listDepth += 1;
return "\n\n";
}
Comment on lines +152 to +156

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📝 Info: Dropping the list marker shifts inferred indentation unit

An opening <ul>/<ol> no longer emits a width-4 marker (postBodyDisplay.ts:152-156), so it no longer feeds the GCD in inferIndentationUnit (postBodyDisplay.ts:252). When every list-item declared width is a multiple of 8, the inferred unit rises (GCD 8 instead of 4), halving computed indent levels versus before. No test covers this.

Open in Devin Review

Was this helpful? React with 👍 or 👎 to provide feedback.

if (closing) return "\n\n";
const nestedListIndent = !closing && listDepth > 0 ? Math.max(0, listDepth - 1) * 4 : 0;
return `\n\n${indentMarker(declaredIndentWidth(tag) + nestedListIndent)}`;
Comment on lines +158 to +159

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📝 Info: Nested-list markers rely on paragraph splitting to avoid double-counting

A nested <li> and its child <p> each emit an equal-width indent marker (postBodyDisplay.ts:158-159). Double-counting is avoided only because block tags insert \n\n between them, so the <li> marker forms its own paragraph that strips to empty and is dropped in pushText. If that separation ever changes, wrapped list items would indent twice as deep.

Open in Devin Review

Was this helpful? React with 👍 or 👎 to provide feedback.

})
.replace(WORD_INDENT_TAG, (tag) => indentMarker(declaredIndentWidth(tag)));
const withoutTags = withBoundaries.replace(HTML_TAG, (tag) => {
Expand Down