feat: preserve #anchor in wikilinks - #10
Draft
srid wants to merge 7 commits into
Draft
Conversation
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.
…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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Wiki-links like
[[note#heading]]now carry the anchor through to theB.LinkURL field — the parser captures the fragment,wikilinkInlineappends it viaanchorSuffix, anddelineateLink(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
urlResolvingSplicealready appendsmAnchorto the resolved site-route URL, so no rendering changes are needed there — wiring is just a flake input bump.Breaking API changes
wikilinkInlinegains aMaybe Anchorparameter.mkWikiLinkFromInlinereturns(WikiLink, Maybe Anchor, [Inline]).HasWikiLink.wikilinktypeclass method takesMaybe Anchor. (Unexported, but listed for completeness.)Version bumped to 0.4.0.0.
Test coverage
[[a#b]],[[a#b]]#,#[[a#b]],![[a#b]].[[a#b|c]].plainifyround-trip for the raw form[[a#b]]and the custom-title form.Test plan
cabal test allpasses on the new branch