Skip to content

Conversation

@kepano
Copy link

@kepano kepano commented Sep 12, 2025

Add Obsidian-Flavored Markdown #9883 using Markdown extensions.

Extensions

  • comments: Parses %%text%% as comments (removed from output)
  • wikilink_transclusions: Parses ![[Title]] for full file transclusion
  • wikilink_heading_transclusions: Parses ![[Title#Heading]] for heading transclusions
  • wikilink_block_transclusions: Parses ![[Title#^id]] for block transclusions
  • block_ids: Parses ^id at paragraph end, wraps paragraph in Div with that ID

Uses insertIncludedFile for transclusion.

Includes tests and manual updates.

@jgm
Copy link
Owner

jgm commented Sep 12, 2025

Transclusion should be possible. See insertIncludedFile from Text.Pandoc.Parsing.
And look at the RST reader's treatment of include directives for an example of its use.

@kepano
Copy link
Author

kepano commented Sep 13, 2025

@jgm I think this is in a good place for your review now.

Some notes:

  1. I revised how wikilink images (e.g. ![[image.jpg]]) are parsed because the implementation of Image wikilinks for export in Obsidian #8853 via 09de84f seemed to be originally driven by Obsidian's syntax. In Obsidian, the ![[link]] wikilink syntax can be used to transclude any type of file (not just images), as well as headings and blocks within Markdown files. I consolidated all of these into a new transclusion parser (which could alternatively be called "include" or "embed" if you prefer).
  2. I ended up building on top of the Markdown reader instead of the Commonmark reader. Hopefully this gives flexibility to other apps that support Obsidian's syntax but not other Commonmark extensions.

@kepano kepano changed the title Obsidian extensions Obsidian reader extensions for comments and wikilink transclusions Sep 13, 2025
@kepano kepano force-pushed the obsidian-extensions branch from 479d5f1 to 7b2638d Compare September 17, 2025 01:33
@jgm
Copy link
Owner

jgm commented Sep 17, 2025

Can you rebase this into one commit, or a few logically coherent commits? All API changes should be clearly described and marked as such [API change] in the commit messages, so we won't miss them in the changelog.

@kepano kepano force-pushed the obsidian-extensions branch 3 times, most recently from 626148c to dbd8cdf Compare September 17, 2025 16:10
@kepano kepano force-pushed the obsidian-extensions branch from dbd8cdf to ad204c0 Compare September 17, 2025 16:20
@kepano
Copy link
Author

kepano commented Sep 17, 2025

Can you rebase this into one commit, or a few logically coherent commits? All API changes should be clearly described and marked as such [API change] in the commit messages, so we won't miss them in the changelog.

Done!

@jgm
Copy link
Owner

jgm commented Nov 30, 2025

Re block_transclusions, heading_transclusions: are these really transclusions? From the docs, it looks like they just produce links.

@jgm
Copy link
Owner

jgm commented Nov 30, 2025

Does block_ids also handle the case where the id is on a line by itself before a block? And the case where it is meant to apply to a a line inside a block?

@pidgeon777
Copy link

Hello, thanks for working on it. What about Obsidian callouts? Do you think those are doable also?

@kepano
Copy link
Author

kepano commented Nov 30, 2025

@jgm Thanks for the update. I saw a notification from you about other requested changes on #9883 but it seems you removed that comment. Is there something else you want me to work on?

Re block_transclusions, heading_transclusions: are these really transclusions? From the docs, it looks like they just produce links.

They are indeed transclusions, not links. The content within the source block or heading is transcluded into the document. See also this documentation page about embeds. In Obsidian-Flavored Markdown adding an exclamation mark ! before a wikilink changes it to a transclusion (AKA embed), e.g. [[link]] or ![[transclusion]], the additional modifiers #^ and # provide access to the block or heading.

Does block_ids also handle the case where the id is on a line by itself before a block? And the case where it is meant to apply to a a line inside a block?

I'll check and add tests for this.

Hello, thanks for working on it. What about Obsidian callouts? Do you think those are doable also?

Callouts are already handled by the alerts extension — the GitHub syntax was inspired by Obsidian.

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.

3 participants