Skip to content

Obsidian-style ^blockid block-ID definition syntax #749

Description

@srid

Follow-up to #105 / #748.

PR #748 lands heading anchors for wiki-links — [[note#heading]] jumps to the matching pandoc heading id on the target page. The link side of Obsidian block references is the same syntax with a caret-prefixed anchor ([[note#^565948]]), and the permissive anchor parser added in #748 already carries the caret through to the rendered href — i.e. clicking the link will navigate to note.html#^565948. Verified by a parser-spec test.

What's missing is the definition side — Obsidian's non-CommonMark trailing-^blockid marker:

This is a paragraph. ^blockid

- List item ^blockid

> Quoted text ^blockid

For the link to actually scroll the page, the rendered target needs id="^blockid" (or id="blockid") on the corresponding block. Today Emanote does nothing with these markers — they pass through as literal text.

Proposed approach

A pandoc filter (Haskell, parse-time) that walks blocks and:

  1. Detects a trailing Str "^<blockid>" token (or Space, Str "^<blockid>") as the last inline of a block.
  2. Strips the marker token from the block's inlines.
  3. Wraps (or annotates) the block with the corresponding id attribute so anchor navigation works.

Block kinds to support: Para, the last inline of an item in OrderedList / BulletList, BlockQuote, Header. Code blocks and figure captions should likely be excluded (Obsidian itself behaves that way).

Constraints

  • Non-CommonMark. This is Obsidian-only — guard behind a config flag or an opt-in pandoc filter, since it changes the meaning of bare ^ in text.
  • ID collision. A user might write both ## Heading {#blockid} and Para ^blockid. Pick a precedence rule (probably: header attrs win, since they're explicit pandoc syntax) and document it.
  • Inline-position only. Obsidian's spec is "block ID at end of block." Reject mid-block markers — those are literal text.

Out of scope for this issue

  • Same-file forms [[#heading]] and [[#^blockid]] — deferred in Support [[note#heading]] wiki-link anchors (discussion #105) #748, separate parser change in commonmark-wikilink (empty wikilink slug).
  • Block embedding (![[note#^blockid]] inlining the referenced block) — depends on this issue and on the embed renderer's section-scoped TODO marked in emanote/src/Emanote/Pandoc/Renderer/Embed.hs.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions