pi-mono/packages/tui/src/components
Petr Houška 54280c4ff0
fix(tui): hide HTML comments in Markdown rendering (#11755)
Fixes #11710.

## Problem

The tui `Markdown` component printed `<!-- ... -->` comments verbatim.
marked lexes them as `html` tokens and both the block and inline `html`
cases pushed `token.raw` as text, so comments leaked into every Markdown
surface (Extension Updates, What's New, `/changelog`, messages).

```
## [1.0.0]

<!-- release-notes:start -->
Fixed a bug.

See <!-- todo: link --> the docs.
```

rendered both comments.

## Fix

- After lexing (next to `trimPartialClosingFences`, before tokens are
cached), remove block `html` tokens that contain only comments,
recursing into lists and blockquotes. If the removed comment sat between
two blank lines, or at the start/end, one blank line is dropped too, so
no extra gap remains.
- Block HTML with other content keeps rendering as text, with comments
stripped (`<!-- x --> text` renders `text`).
- Inline comments are skipped; if text before ended with a space, the
next text's leading space is dropped (`See <!-- c --> the docs.` renders
`See the docs.`).
- An unclosed block comment runs to the end of the block (CommonMark),
so streamed comments stay hidden.
- Other HTML still renders as text (`with <tag> markers`).

Parsing stays in marked; the change only filters tokens marked already
produced. Cost: one pass over top-level tokens per lex (cached), a regex
on `html` tokens only.

## Tests

`packages/tui/test/markdown.test.ts`, "HTML comments": compares
rendering with comments against the same Markdown without them (issue
repro, blank-line handling, multi-line/unclosed, blockquotes and lists,
other HTML kept).

This PR is AI-generated.
2026-11-03 22:33:03 +01:00
..
alt-screen-flash.ts feat(tui): add stacked alt-screen flashes (#7361) 2026-07-31 10:13:31 +02:00
box.ts fix(coding-agent): apply outputPad to all transcript blocks (#10557) 2026-10-06 17:27:55 +02:00
cancellable-loader.ts chore(ts): use source import extensions 2026-05-20 00:04:03 +02:00
editor.ts fix(tui,coding-agent): handle selection page keys in all scrolling lists 2026-10-28 19:05:21 +01:00
h-stack.ts feat(tui): add alternate-screen viewport layouts 2026-07-31 09:22:10 +02:00
image.ts fix(tui,coding-agent): convert non-PNG images for Kitty in Image 2026-10-03 00:14:52 +02:00
input.ts feat(tui,coding-agent): use only the terminal cursor when showHardwareCursor is enabled 2026-10-08 00:23:06 +02:00
loader.ts feat(tui): prettier Working... spinner (#8799) 2026-09-03 20:34:04 +02:00
markdown.ts fix(tui): hide HTML comments in Markdown rendering (#11755) 2026-11-03 22:33:03 +01:00
mouse-region.ts feat(tui): add reusable mouse interaction support 2026-08-14 15:26:27 +02:00
scroll-view.ts feat(tui): alt mode scrollbar but prettier (#8801) 2026-09-04 00:05:47 +02:00
select-list.ts fix(tui,coding-agent): handle selection page keys in all scrolling lists 2026-10-28 19:05:21 +01:00
settings-list.ts fix(tui,coding-agent): handle selection page keys in all scrolling lists 2026-10-28 19:05:21 +01:00
spacer.ts chore(ts): use source import extensions 2026-05-20 00:04:03 +02:00
stack.ts feat(tui): add alternate-screen viewport layouts 2026-07-31 09:22:10 +02:00
text.ts fix(coding-agent,tui): reuse syntax highlighting and rendered Markdown blocks 2026-11-01 14:40:56 +01:00
truncated-text.ts chore(ts): use source import extensions 2026-05-20 00:04:03 +02:00
v-stack.ts fix(tui): honor nested stack minimum sizes 2026-08-04 12:44:59 +02:00