Skip to content

Resolve derived titles to plain text#94

Merged
Renakoni merged 1 commit into
mainfrom
fix/draft-title-inline-html
Jul 10, 2026
Merged

Resolve derived titles to plain text#94
Renakoni merged 1 commit into
mainfrom
fix/draft-title-inline-html

Conversation

@Renakoni

Copy link
Copy Markdown
Owner

Summary

Fixes the clunky titles reported for styled first lines: a draft starting with ***<u>alpha</u>*** bravo charlie delta used to lose its emphasis markers but keep the raw <u> tags, so the home list showed <u>alpha</u> bravo charlie delta. Derived titles now always resolve to plain text — <u>alpha</u> … and ***<u>alpha</u>*** … both title as alpha bravo charlie delta.

Kept deliberately separate from #93: this is a user-visible behavior fix on the web side, while the decomposition series PRs are behavior-preserving by contract.

Change

  • New shared stripInlineMarkdown reduction in documentState.ts: keeps link/image text, drops inline HTML tags and emphasis markers, collapses whitespace.
  • Applied on both title paths, since the same leak existed one # away: the leading-line heuristic from Name untitled drafts from their first meaningful line #83 and the heading branch (# **Trip** to <u>Paris</u> now titles as Trip to Paris).
  • The tag pattern matches raw HTML the way CommonMark does (letter-led tag name, optional attributes, optional self-close), so autolinks like <https://example.com> are treated as content and preserved.
  • A heading that reduces to pure markup (# ***) now names nothing and falls through to the display-name/leading-text fallbacks instead of titling the document as a row of asterisks.

Titles are derived, never stored as user input, so existing documents pick up clean titles on their next open/save with no migration.

Testing

  • Three new/extended unit cases lock the reported case verbatim (with and without emphasis), tag variants (<mark>, <br> word spacing), autolink preservation, styled-heading reduction, and the pure-markup-heading fall-through. documentState suite 23/23.
  • Full unit suite 310/310, ESLint, vue-tsc, production build green.

Draft and heading titles previously leaked markup: a first line like
"***<u>alpha</u>*** bravo" lost its emphasis markers but kept the raw
<u> tags, and a styled heading was surfaced verbatim. Titles now reduce
to plain text through a shared stripInlineMarkdown helper used by both
the leading-line and heading paths: link/image text is kept, inline
HTML tags are dropped, and paired delimiters are unwrapped.

Only actual markup is removed. Paired code spans, asterisk emphasis,
GFM strikethrough, and underscore emphasis (per CommonMark's rule that
intraword underscores never emphasize) unwrap to their content, so
literal punctuation like file_name, snake_case_name, 2*3, or foo~bar
survives, including in suggested file names derived from titles.
Marker-only runs reduce to nothing and fall through to the
display-name and leading-text fallbacks.

The tag pattern matches raw HTML the way CommonMark does: letter-led
names including hyphenated custom elements, attributes whose quoted
values may contain closing angle brackets, optional self-close.
Autolinks like <https://example.com> and <user@example.com> remain
content.
@Renakoni Renakoni force-pushed the fix/draft-title-inline-html branch from 3adad9e to 3c4223c Compare July 10, 2026 14:41
@Renakoni

Copy link
Copy Markdown
Owner Author

Both review points addressed in the updated commit (also rebased onto current main, so the merge commit is gone and the branch is a single commit again):

1. Literal punctuation preserved. The global [*_~]deletion is gone.stripInlineMarkdown` now only unwraps actual paired delimiters:

  • code spans `...`
  • asterisk emphasis *{1,3}...*{1,3}
  • underscore emphasis with CommonMark's intraword rule — _ flanked by letters/digits ((?<![\p{L}\p{N}])_{1,3}([^_]+)_{1,3}(?![\p{L}\p{N}])) never counts as markup
  • GFM strikethrough ~~...~~ only (single ~ is content)

So # file_namefile_name, # 2*3 benchmark2*3 benchmark, # foo~barfoo~bar, and suggested filenames keep their underscores. One behavior note: with paired unwrapping, a marker-only heading like # *** no longer collapses to empty by accident, so the helper now explicitly treats a reduction consisting solely of marker characters as "no title" — the existing # *** → fall-through-to-content test kept passing because of this rule.

2. Inline HTML tag pattern fixed. Now /<\/?[a-z][a-z0-9-]*(?:[\s\/](?:[^<>"']|"[^"]*"|'[^']*')*)?>/gi:

  • hyphenated custom elements match (<my-widget>alpha</my-widget> betaalpha beta)
  • quoted attribute values may contain > (<span title="a>b">alpha</span> betaalpha beta, no leaked b">)
  • autolinks still don't match because the character after the tag name must be whitespace, /, or ><https://…> and <user@…> remain content (covered by tests)

Added the three suggested heading regressions plus snake_case_name, ~~done~~, _emphasized_, the custom-element case, the quoted-attribute case, and an email-autolink case. Full suite 312/312, lint and build clean.

@Renakoni Renakoni merged commit c7facd1 into main Jul 10, 2026
5 checks passed
@Renakoni Renakoni deleted the fix/draft-title-inline-html branch July 10, 2026 14:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant