fix(markdown): render anchors without a stray close tag and keep <details> summaries as direct children

Two raw-HTML preview defects (client rendering only, no DSH source touched):

- A stray `</a>` from an author's `<a id="x"></a>` was printed as literal text.
  The host renderer emits one text node per raw-HTML token, so the open tag and
  its close tag arrive as siblings; DOMPurify drops a lone close tag (no element
  children), which fell into the inline pass's "no elements means prose, keep
  the text" branch. The pass now deletes a node that is nothing but a close tag,
  keeping the anchor id and leaving comparison prose (`a < b`, `x </ y`) intact.
- A `<details>` fold showed the UA's own "Details" label while the authored
  summary text dropped into the body: `<summary>…</summary>` is a balanced span,
  so analyzeHtmlSegment reduced it to an `html` leaf wrapped in a block div,
  which is not a direct child of `<details>` and therefore not honored as the
  disclosure widget. The renderer now hoists a leaf-leading summary into a real
  `<summary>` element inside its details frame (attributes via the shared props
  extraction, media/anchors still hardened), with no hardcoded label.

Also scope `.editorMd details > summary { cursor: pointer }` so a hoisted
summary keeps its pointer cursor (the old `.editorHtmlBlock summary` rule no
longer matches once it leaves the leaf wrapper).

Tests: 8 new/tightened cases in tests/markdown-html-render.spec.tsx (13 -> 21),
plus a seeded anchor and direct-child summary assertions in the real mount
smoke (tests/e2e/mount.e2e.ts). Verified pnpm test (113 files / 1140 passed),
typecheck, lint, and pnpm test:mount (7/7).

Fixes #778
This commit is contained in:
ymac committed 2026-09-27 19:45:17 +08:00
1 parent ad6b0b1486
commit f5ffd10474
4 files changed
+272 -18

No files matched your search

+5 -1
View File
@@ -2117,7 +2117,11 @@ body[data-dsh-sidebar-dragging] .bottomPanel {
padding: 4px 0;
}
.editorHtmlBlock summary {
/* A `<summary>` the renderer hoisted out of a leaf is a direct child of its
`<details>` (see MarkdownHtml.tsx), so it no longer sits inside
`.editorHtmlBlock` — match it against the preview container too. */
.editorHtmlBlock summary,
.editorMd details > summary {
cursor: pointer;
}