fix(topic): keep URLs, aliases and user IDs intact in room topics (#262) #427

Merged
jared merged 1 commits from fix/topic-markdown into lotus 2026-10-19 14:41:04 -04:00
Owner

Fixes #262.

The topic editor had its own markdown converter, which treated any _ or * as emphasis, including inside URLs, #alias:server and @user:server. It then built the plain topic by stripping tags, so the underscores were lost for every client. It didn't escape " either.

Now: utils/topicMarkdown.ts → buildTopicContent()

  • Uses the composer's inline markdown parser (the same rules as messages), which handles links, bare URLs and HTML escaping.
  • One topic-specific guard: an _ between two letters or digits is literal, as in CommonMark. Inline code, link targets and URLs are left alone, so no stray backslashes appear.
  • Plain topic: markers dropped, links kept as text (url), entities decoded. Text with no markdown is sent exactly as typed, with no formatted body.
  • I didn't change the shared parser itself: that would change how every message renders.

Verified

  • 10 unit tests: the issue's three examples, emphasis at word boundaries, emphasis around an alias, inline code, the " breakout, HTML escaping, line breaks, plain text.
  • Browser, through the real editor, read back from Synapse:
    • Rules: https://wiki.lotusguild.org/en/server_rules_and_faq → topic is identical, with no formatted body.
    • [Our wiki](https://wiki.example.org/my_cool_page) and **Join #my_room_name:matrix.org** → topic: Our wiki (https://wiki.example.org/my_cool_page) and Join #my_room_name:matrix.org; formatted_body: <a data-md href="https://wiki.example.org/my_cool_page">Our wiki</a> and <strong data-md="**">Join #my_room_name:matrix.org</strong>. The header shows both intact.

🤖 Generated with Claude Code

https://claude.ai/code/session_017PCb59uY3UKqDqt7B6hzd5

Fixes #262. The topic editor had its own markdown converter, which treated **any** `_` or `*` as emphasis, including inside URLs, `#alias:server` and `@user:server`. It then built the plain `topic` by stripping tags, so the underscores were lost **for every client**. It didn't escape `"` either. **Now:** `utils/topicMarkdown.ts` → `buildTopicContent()` - Uses the **composer's inline markdown parser** (the same rules as messages), which handles links, bare URLs and HTML escaping. - One topic-specific guard: an `_` between two letters or digits is literal, as in CommonMark. Inline code, link targets and URLs are left alone, so no stray backslashes appear. - Plain `topic`: markers dropped, links kept as `text (url)`, entities decoded. Text with no markdown is sent exactly as typed, with no formatted body. - I didn't change the shared parser itself: that would change how every message renders. **Verified** - 10 unit tests: the issue's three examples, emphasis at word boundaries, emphasis around an alias, inline code, the `"` breakout, HTML escaping, line breaks, plain text. - Browser, through the real editor, read back from Synapse: - `Rules: https://wiki.lotusguild.org/en/server_rules_and_faq` → `topic` is identical, with no formatted body. - `[Our wiki](https://wiki.example.org/my_cool_page) and **Join #my_room_name:matrix.org**` → `topic`: `Our wiki (https://wiki.example.org/my_cool_page) and Join #my_room_name:matrix.org`; `formatted_body`: `<a data-md href="https://wiki.example.org/my_cool_page">Our wiki</a> and <strong data-md="**">Join #my_room_name:matrix.org</strong>`. The header shows both intact. 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_017PCb59uY3UKqDqt7B6hzd5
jared added 1 commit 2026-10-19 14:11:21 -04:00
fix(topic): keep URLs, aliases and user IDs intact in room topics (#262)
CI / Build & Quality Checks (pull_request) Successful in 1m48s
CI / Trigger Desktop Build (pull_request) Skipped
CI / Docker image build & smoke test (pull_request) Skipped
CI / Secret scan (gitleaks) (pull_request) Successful in 7s
CI / Playwright smoke (e2e) (pull_request) Successful in 12m19s
ce1354ed93
The topic editor's hand-rolled markdown treated any single _ or * as
emphasis, inside URLs and #alias:server / @user:server too, and built the
plain topic by stripping tags, so the underscores were lost for every
client. It also left " unescaped in link targets.

buildTopicContent() now uses the composer's inline markdown parser (links,
bare URLs and HTML escaping as for messages) and treats _ between two
letters/digits as literal (CommonMark), except inside code, link targets
and URLs. The plain topic drops the markers but keeps links as
"text (url)" and decodes entities.

Fixes #262

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017PCb59uY3UKqDqt7B6hzd5
jared merged commit f5a184e428 into lotus 2026-10-19 14:41:04 -04:00
Sign in to join this conversation.
No Reviewers
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: LotusGuild/cinny#427