Skip to content

feat(web): comment anchors and #N auto-linking - #24

Merged
Void-n-Null merged 1 commit into
VoidNullable:masterfrom
unger1984:feat/comment-anchors
Aug 11, 2026
Merged

feat(web): comment anchors and #N auto-linking#24
Void-n-Null merged 1 commit into
VoidNullable:masterfrom
unger1984:feat/comment-anchors

Conversation

@unger1984

Copy link
Copy Markdown
Contributor

Problem

Agents and humans frequently reference specific comments as #42, but there is no visible comment number in the UI and no way to navigate to that comment. The link is dead — it goes nowhere. For a project whose primary users are agents referencing each other's comments, this is a meaningful gap.

The comment id already exists in the DB and is returned by the API. The DOM anchor id="comment-{id}" on each <li> and the scroll infrastructure (commentTargetFromHash in commentLinks.ts) were already in place — the web UI simply wasn't surfacing the number or generating links to it.


Changes

Comments.svelte — adds a clickable #N link to each comment header. Clicking it updates the URL hash and scrolls to the comment (the existing scroll infrastructure picks it up automatically).

Markdown.svelte — two new post-processing passes modelled on the existing linkIdentifiers:

  • linkCrossCommentRefsWS-25#comment-42 in text becomes a link to issue WS-25 with ?comment=42, which commentTargetFromHash uses to scroll to the right comment on page load. Runs first so the full IDENT#comment-N token is consumed before IDENTIFIER_RE can grab WS-25 alone.
  • linkCommentRefs — a bare #42 in text becomes #comment-42 on the current page. Runs after linkIdentifiers.

Both passes use the same tag-aware walk as linkIdentifiers (<a>/\<code>/\<pre> are skipped). No conflict with issue identifiers (WS-25, APP-42) — those always carry an alphabetic project prefix.

Backend unchanged.


Verification

  • Existing identifier linking (WS-25 → issue) unaffected
  • # heading and #42 are not linked
  • cargo clippy --all-targets -- -D warnings — clean
  • cargo test --all-targets — 1229 passed, 0 failed

Each comment header now shows a clickable #N link that scrolls to the
comment and sets the URL hash. Bare #N references in markdown text are
auto-linked to #comment-N on the same page. Cross-issue WS-25#comment-42
references are linked to the target issue with a ?comment= query that
scrolls to the right comment on load.

Both new passes (linkCrossCommentRefs, linkCommentRefs) follow the existing
linkIdentifiers pattern: tag-aware token walk, skip inside <a>/<code>/<pre>.
Pipeline order: linkCrossCommentRefs → linkIdentifiers → linkCommentRefs
so the full IDENT#comment-N token is consumed before IDENTIFIER_RE can
grab IDENT alone.
Void-n-Null added a commit that referenced this pull request Aug 11, 2026
The bare-#N comment-ref pass (PR #24) runs on marked's HTML output,
where apostrophes are escaped as &#39;. Its lookbehind excluded
alphanumerics but not '&', so every apostrophe in rendered markdown
was mangled: "don't" became "don&" + a bogus #39 comment link + ";t".
Add '&' to the lookbehind so numeric entities pass through untouched.

Verified against the real marked/DOMPurify pipeline: entities render
intact, legitimate #N refs (start of line, after spaces, after
punctuation) still link.
@Void-n-Null
Void-n-Null merged commit 3dc1428 into VoidNullable:master Aug 11, 2026
@Void-n-Null

Copy link
Copy Markdown
Collaborator

Great feature, merged. Thanks for modeling it on the existing pipeline for linkIdentifiers, made review easy.

pushed a small follow-up that just fixed a small HTML output bug where apostrophes would escape as '
which would randomly put #39 as a comment link.

I apologize for the wait to merge, should be quicker going forward if you have any other contributions you were considering.

@unger1984
unger1984 deleted the feat/comment-anchors branch August 11, 2026 17:57
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.

2 participants