Skip to content

feat: preserve #anchor in wikilinks - #10

Draft
srid wants to merge 7 commits into
masterfrom
heading-link
Draft

feat: preserve #anchor in wikilinks#10
srid wants to merge 7 commits into
masterfrom
heading-link

Conversation

@srid

@srid srid commented May 27, 2026

Copy link
Copy Markdown
Owner

Wiki-links like [[note#heading]] now carry the anchor through to the B.Link URL field — the parser captures the fragment, wikilinkInline appends it via anchorSuffix, and delineateLink (already prepared) round-trips it back as (WikiLink, Just Anchor). The two TODOs in this file referencing srid/emanote#105 are now resolved.

Downstream, emanote's urlResolvingSplice already appends mAnchor to the resolved site-route URL, so no rendering changes are needed there — wiring is just a flake input bump.

Breaking API changes

  • wikilinkInline gains a Maybe Anchor parameter.
  • mkWikiLinkFromInline returns (WikiLink, Maybe Anchor, [Inline]).
  • HasWikiLink.wikilink typeclass method takes Maybe Anchor. (Unexported, but listed for completeness.)

Version bumped to 0.4.0.0.

Test coverage

  • Anchor preservation across all four wikilink types: [[a#b]], [[a#b]]#, #[[a#b]], ![[a#b]].
  • Custom-title form [[a#b|c]].
  • Anchor with spaces.
  • plainify round-trip for the raw form [[a#b]] and the custom-title form.

Test plan

  • cabal test all passes on the new branch
  • Downstream emanote integration build green

srid added 3 commits May 26, 2026 22:00
Wiki-links like [[note#heading]] now carry the anchor through to the
B.Link URL field (rendered as 'note#heading' instead of 'note'), so
downstream consumers — most importantly emanote's link resolver — can
forward the fragment to the final href. Resolves the long-standing
TODO marked in this file and unblocks emanote/discussions/105.

Breaking: wikilinkInline gains a 'Maybe Anchor' parameter and
mkWikiLinkFromInline returns an extra Maybe Anchor component.
…ding in plainify'

wikiLinkInlineRendered already uses 'let target = wikilinkUrl wl <> anchorSuffix manc';
plainify' open-coded the same composition. Lift it to a let here too so
the two sites can't drift on anchor handling. Kept local; not exported —
the formula is composition of two already-volatile primitives, not its
own API surface.
srid added 3 commits May 27, 2026 19:18
…raw URL input

Non-Markdown callers (MCP tools, CLI, JSON APIs) receive the
inside-the-brackets text of a wikilink as a plain string and need
the same target+anchor semantics as the renderer. Add a single helper
'parseWikiLinkUrl :: Text -> Maybe (WikiLink, Maybe Anchor)' that
handles slash-splitting and anchor stripping in one call. Mirrors
'delineateLink' for the no-Pandoc-attrs case.
srid added a commit to srid/emanote that referenced this pull request May 27, 2026
Address PR #748 inline review: 'Shouldn't we upstream this to commonmark-wikilink?'

The slash-split + slug-decode + anchor-strip combo that Emanote's MCP
parseWikiLinkText was open-coding is now a single library helper
(srid/commonmark-wikilink#10, commit a3e5938). MCP calls it directly
and discards the anchor with a named pattern + comment so the
asymmetry from the HTML renderer (which keeps the anchor) stays
legible.
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