Skip to content

docs(specs): markdown viewer anchor links (GH13725) - #14965

Open
fbartho wants to merge 7 commits into
warpdotdev:masterfrom
fbartho:fb/13725-anchors-spec
Open

fbartho wants to merge 7 commits into
warpdotdev:masterfrom
fbartho:fb/13725-anchors-spec

Conversation

@fbartho

@fbartho fbartho commented Aug 11, 2026

Copy link
Copy Markdown
Contributor

Closes #13725

Product + technical spec for anchor links in the Markdown viewer: raw <a href> links, explicit <a id>/<a name> targets, GitHub-style heading slugs, and cross-document fragments (other-file.md#section).

#13962 remains open as the implementation this spec describes.

Product and tech spec for raw `<a href>`/`<a id>` anchor links and
in-document fragment navigation in the Markdown viewer.

The viewer already has the click branch, the scroll primitive, and a
per-click heading walk; the defect is that find_matching_header compares
a fragment against a heading's exact lowercased text, so a hyphenated
`#target-section` cannot match a heading reading "Target Section". The
spec scopes the fix to a Unicode-preserving slug normalizer applied to
both sides of that comparison, plus an `<a href>` inline token reusing
the existing Hyperlink::Url styling, explicit anchor targets resolved by
the same click-time walk, and cross-document fragment navigation with
its three prerequisite resolution repairs.

All file:line references verified against master at 495f975.
The spec described the design but not what ships together. Add a
delivery-scope section grouping the sixteen invariants into the three
slices the work decomposes into, and a matching sequencing note in the
tech spec explaining why that order holds (the explicit-target work
reuses the heading resolver; cross-document navigation carries the
three resolution repairs as prerequisites).

Record the visible-literal-anchor-text limitation as current intended
behavior rather than a deferred gap: hiding the tag needs a
save-round-trippable content-model representation, tracked as warpdotdev#13982.
@cla-bot cla-bot Bot added the cla-signed label Aug 11, 2026
@github-actions github-actions Bot added the external-contributor Indicates that a PR has been opened by someone outside the Warp team. label Aug 11, 2026
@fbartho
fbartho marked this pull request as ready for review August 12, 2026 16:12
@warp-for-oss

warp-for-oss Bot commented Aug 12, 2026 •

Copy link
Copy Markdown
Contributor

@fbartho

I'm starting a first review of this spec-only pull request.

You can view the conversation on Warp.

I completed the review and no human review was requested for this pull request.

Comment /oz-review on this pull request to retrigger a review (up to 3 times on the same pull request).

Powered by Oz

@warp-for-oss warp-for-oss Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overview

This spec PR defines product and technical behavior for Markdown viewer anchor links, including raw <a href> parsing, heading slug resolution, explicit <a id>/<a name> targets, and cross-document fragments.

Concerns

  • The technical plan contradicts the product invariant for <a> tags that carry both href and id/name: the parser section says non-href attributes are discarded, while the product spec requires the same tag to render as a link and register a jump target.
  • The explicit-anchor resolver is specified as a live text scan, but the spec does not explain how it avoids registering <a id> markup inside code spans or fenced code blocks, which the product spec says must remain literal and non-anchor.

Verdict

Found: 0 critical, 2 important, 0 suggestions

Request changes

Comment /oz-review on this pull request to retrigger a review (up to 3 times on the same pull request).

Powered by Oz

Comment thread specs/GH13725/tech.md Resolved
Comment thread specs/GH13725/tech.md Resolved
Address two review findings on the anchor-target resolver, both rooted
in the spec asserting a mechanism without saying which text
representation it reads.

Dual-role tags: state that the scan runs over buffer source text, so an
`id` is visible whether or not the parser tokenized the tag. The parser
keeps only `href` and discards other attributes, so a scan pattern bound
to `id`/`name` immediately after `<a` matches `<a id=… href=…>` but
misses `<a href=… id=…>`. Require attribute-order independence and pin
both orders in tests, rather than weakening invariant 11.

Code exclusion: parse-time `CodeSpan` consumption keeps anchor markup in
code from rendering as a link, but says nothing about the click-time
scan, which reads the source text where code content is still present.
Specify per-block exclusion of `BufferBlockStyle::CodeBlock` via the
outline walk the resolver already performs, plus fragment-level
rejection of matches inside inline-code spans, and add resolution
coverage for both.

Sweep for siblings of the same miss-cause: qualify the feasibility
summary and product invariants 5 and 10, and correct the dual-role
non-goal, which read as declining support that invariant 11 requires.
@fbartho

fbartho commented Aug 13, 2026

Copy link
Copy Markdown
Contributor Author

/oz-review

@warp-for-oss

warp-for-oss Bot commented Aug 13, 2026 •

Copy link
Copy Markdown
Contributor

@fbartho

I'm re-reviewing this spec-only pull request in response to a review request.

You can view the conversation on Warp.

I completed the review and no human review was requested for this pull request.

Comment /oz-review on this pull request to retrigger a review (up to 3 times on the same pull request).

Powered by Oz

@warp-for-oss warp-for-oss Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overview

This PR adds product and technical specs for Markdown viewer anchor links, including raw HTML <a href> parsing, explicit <a id>/<a name> targets, GitHub-style heading slugs, same-document scrolling, and cross-document fragments.

Concerns

  • The cross-document fragment plan specifies decoding the fragment during link resolution, then reusing the existing fragment resolver that already expects and decodes #-prefixed URLs, leaving encoded fragments and pending-anchor representation ambiguous.
  • The slug algorithm wording conflicts on whether punctuation removal is ASCII-only or Unicode-category-based, which could cause incompatible behavior for non-ASCII punctuation.

Verdict

Found: 0 critical, 1 important, 1 suggestions

Request changes

Comment /oz-review on this pull request to retrigger a review (up to 3 times on the same pull request).

Powered by Oz

Comment thread specs/GH13725/tech.md Resolved
Comment thread specs/GH13725/tech.md Resolved
… scope

Fragment representation had two layers each claiming the decode. Item 5
split the fragment off a path and decoded it, while the resolver it hands
off to strips a required leading `#` and decodes again, so a percent-encoded
cross-document anchor either double-decoded or missed outright. State the
representation once in item 3 -- raw, percent-encoded, `#` retained, with
the resolver owning the single decode -- and make the split, the pending
anchor, and the tests defer to it.

The slug rule opened with an ASCII-only exclusion set and closed by calling
the exclusion category-based. GitHub strips punctuation by Unicode general
category, so the ASCII reading kept `。` and `?` in slugs and broke parity
for non-English headings in a way the letters-only test table could not
catch. Specify `P*`/`S*` with the literal hyphen excepted, correct the
attribution (cmark-gfm emits no heading ids), and add the non-ASCII
punctuation cases.

Also states whether rich inline content inside `<a href>` is supported,
which product invariant 9 requires the tech spec to answer.
@fbartho

fbartho commented Aug 19, 2026

Copy link
Copy Markdown
Contributor Author

/oz-review

@warp-for-oss

warp-for-oss Bot commented Aug 19, 2026 •

Copy link
Copy Markdown
Contributor

@fbartho

I'm re-reviewing this spec-only pull request in response to a review request.

You can view the conversation on Warp.

I completed the review and no human review was requested for this pull request.

Comment /oz-review on this pull request to retrigger a review (up to 3 times on the same pull request).

Powered by Oz

@warp-for-oss warp-for-oss Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overview

This PR adds product and technical specs for Markdown viewer anchor links, including raw <a href> parsing, explicit <a id>/<a name> targets, GitHub-style heading slugs, and cross-document fragments.

Concerns

  • The technical spec relies on a source-text scan for dual-role <a href ... id=...> tags, but the current markdown loading path converts source markdown into formatted buffer runs, so the spec needs a concrete data path for the authored opening tag after the parser consumes it.
  • The slug algorithm is internally inconsistent with its own GitHub-parity citation for connector punctuation such as underscores.
  • The feature-gating section suggests partial shipment even though the product and sequencing sections state all invariants ship as one deliverable.
  • The test plan should explicitly cover self-closing explicit anchors, which the product spec includes.

Verdict

Found: 0 critical, 3 important, 1 suggestions

Request changes

Comment /oz-review on this pull request to retrigger a review (up to 3 times on the same pull request).

Powered by Oz

Comment thread specs/GH13725/tech.md Resolved
Comment thread specs/GH13725/tech.md Resolved
Comment thread specs/GH13725/tech.md Resolved
Comment thread specs/GH13725/tech.md Resolved
The slug rule stated removal of every Unicode P*/S* category with the
ASCII hyphen excepted, which over-strips connector punctuation. GitHub
preserves `_`: github-slugger's generated class carves 0x5F and 0x2D out
of its ASCII removal ranges, html-pipeline's `\p{Word}` includes Pc, and
`POST /markdown` on `## snake_case_name` returns `snake_case_name`.
Restate the algorithm as an allow-list (L*, M*, Nd, Pc, ASCII hyphen,
whitespace) and pin the discriminating case in the test table.

Item 3 assumed a click-time scan could read authored source out of the
buffer. It cannot: `text_in_range` resolves through
`StyledTextBlock::text()`, which concatenates surviving run strings, and
no run, block, or style retains a raw source span. A consumed dual-role
`<a href id>` would keep only `href` as `TextStylesWithMetadata.link`,
losing the id with no way to recover it. Exclude id-bearing tags from
the `<a href>` grammar so they fall through to literal text, keeping the
scan premise true for every id-bearing form.

The inline-code exclusion had the same defect, directing the implementer
to check fragment ranges through an API that returns style-free text.
Name `range_to_formatted_text`, which is public and carries
`styles.inline_code`; `styled_blocks_in_range` is `pub(super)` and
unreachable from the resolver's crate.

Scope the feature flag to internal rollout so it stops licensing the
partial shipment the delivery-scope section forbids, make the three
delivery groups disjoint, and pin the self-closing anchor, scheme-parity,
and list/blockquote cases the product spec scopes but the tests missed.
Dual-role `<a href="…" id="…">` tags perform both roles, matching
GitHub: they render as clickable links and register jump targets. The
grammar consumes them as links again, so the id can no longer be
recovered from document text and must survive as structured metadata.

Carry it as a sibling `anchor_id: Option<String>` on
`FormattedTextStyles` and `TextStylesWithMetadata` rather than widening
`Hyperlink::Url(String)`. The tuple variant is matched positionally at
21 non-test sites across six crates, three unrelated to markdown
anchors, and widening it also forces a decision about the hand-written
`PartialEq` that style consolidation depends on. A sibling field leaves
those sites untouched and models the domain more honestly, since a bare
anchor has an id and no link at all.

The resolver now merges three sources — heading slugs, literal-scanned
anchors, and metadata anchors — in a single ordered traversal, so
first-occurrence-wins holds across source kinds by construction rather
than by sorting. Round-tripping the id through `to_markdown` is a hard
requirement: without it, editing a document containing a dual-role tag
silently deletes the anchor.

Scope invariant 5's visible-tag limitation and the warpdotdev#13982 deferral to
bare and self-closing anchors, which are unaffected by the metadata
path, and drop the non-goal framing that treated the combined form as a
case not worth designing around.
@fbartho

fbartho commented Aug 20, 2026

Copy link
Copy Markdown
Contributor Author

/oz-review

@warp-for-oss

warp-for-oss Bot commented Aug 20, 2026 •

Copy link
Copy Markdown
Contributor

@fbartho

I'm re-reviewing this spec-only pull request in response to a review request.

You can view the conversation on Warp.

I completed the review and no human review was requested for this pull request.

Comment /oz-review on this pull request to retrigger a review (up to 3 times on the same pull request).

Powered by Oz

@warp-for-oss warp-for-oss Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overview

This spec PR defines product and technical requirements for Markdown viewer anchor links, including raw <a href> links, explicit <a id>/<a name> targets, heading slug resolution, same-document scrolling, and cross-document fragments.

Concerns

  • The combined resolver is specified around content.outline_blocks(), but that iterator skips plain-text blocks on master, so the proposed implementation would miss anchors in ordinary paragraphs.
  • The product spec includes anchors inside table cells in the all-in-one delivery scope, while the tech spec defers table-cell verification to #13726 instead of making the dependency or scope boundary explicit.

Verdict

Found: 1 critical, 1 important, 0 suggestions

Request changes

Comment /oz-review on this pull request to retrigger a review (up to 3 times on the same pull request).

Powered by Oz

Comment thread specs/GH13725/tech.md Resolved
Comment thread specs/GH13725/tech.md Resolved
The resolver was specified over `content.outline_blocks()`, whose
iterator advances past every `PlainText` block, so anchors in ordinary
paragraphs were never examined. Widening that iterator is not available
either: `outline_tests.rs` asserts it yields nothing for a plain-text
buffer. Respec the walk over `range_to_formatted_text` per buffer line,
taking offsets from `line_start`/`line_end` because the formatted-text
model carries no positions and several of its variants consume
characters that appear in no fragment.

Table cells are GFM pipe tables, which parse on master independently of
the raw-HTML `<table>` work in warpdotdev#13726, so invariant 15 is deliverable
here rather than deferred. Their stored form flattens every cell to
unstyled plain text, so cells are re-derived through
`table_from_internal_format_with_inline_markdown` and the table-only
`inline_to_markdown` serializer joins `to_markdown` as a save path the
anchor id must survive.

Also drop the blockquote claims: the viewer has no blockquote construct
at any layer, so a `>`-prefixed line is an ordinary paragraph.
@fbartho

fbartho commented Aug 20, 2026

Copy link
Copy Markdown
Contributor Author

I've addressed & resolved all of oz's findings. Can @oss-maintainers authorize another /oz-review?

@warp-for-oss

warp-for-oss Bot commented Aug 20, 2026 •

Copy link
Copy Markdown
Contributor

@fbartho

I'm re-reviewing this spec-only pull request in response to a review request.

You can view the conversation on Warp.

I reviewed this pull request and requested human review from: @kevinyang372.

Comment /oz-review on this pull request to retrigger a review (up to 3 times on the same pull request).

Powered by Oz

@warp-for-oss warp-for-oss Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overview

This PR adds product and technical specs for Markdown viewer anchor links, covering raw <a href> parsing, explicit <a id>/<a name> targets, GitHub-style heading slug resolution, same-document fragment scrolling, cross-document fragments, feature gating, security boundaries, and validation coverage.

Concerns

No blocking concerns found. The spec is internally consistent, identifies the known visible bare-anchor limitation, documents the save/round-trip requirements that prevent anchor-id data loss, scopes TUI behavior separately from GUI behavior, and includes security considerations for link schemes, event-handler attributes, and fragment resolution.

Verdict

Found: 0 critical, 0 important, 0 suggestions

Approve

Comment /oz-review on this pull request to retrigger a review (up to 3 times on the same pull request).

Powered by Oz

@warp-for-oss
warp-for-oss Bot requested a review from kevinyang372 August 20, 2026 21:54
@kevinyang372
kevinyang372 requested review from bnavetta and removed request for kevinyang372 August 25, 2026 22:03
@kevinyang372

Copy link
Copy Markdown
Member

@bnavetta Mind taking a look here as you have more context triaging the original ticket?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cla-signed external-contributor Indicates that a PR has been opened by someone outside the Warp team.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Markdown viewer: support <a href> and <a id> anchor links

2 participants