Skip to content

Commit dbd8cdf

Browse files
committed
[API change] Obsidian-Flavored Markdown extensions, including comments syntax, full file transclusion, heading transclusion, block transclusion
1 parent d820620 commit dbd8cdf

File tree

10 files changed

+968
-25
lines changed

10 files changed

+968
-25
lines changed

MANUAL.txt

Lines changed: 46 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,7 @@ header when requesting a document from a URL:
269269
- `mdoc` ([mdoc] manual page markup)
270270
- `muse` ([Muse])
271271
- `native` (native Haskell)
272+
- `obsidian` ([Obsidian-Flavored Markdown])
272273
- `odt` ([OpenDocument text document][ODT])
273274
- `opml` ([OPML])
274275
- `org` ([Emacs Org mode])
@@ -503,6 +504,7 @@ header when requesting a document from a URL:
503504
[Jira]: https://jira.atlassian.com/secure/WikiRendererHelpAction.jspa?section=all
504505
[txt2tags]: https://txt2tags.org
505506
[EPUB]: http://idpf.org/epub
507+
[Obsidian-Flavored Markdown]: https://help.obsidian.md/obsidian-flavored-markdown
506508
[OPML]: http://dev.opml.org/spec2.html
507509
[OpenDocument XML]: https://www.oasis-open.org/2021/06/16/opendocument-v1-3-oasis-standard-published/
508510
[ODT]: https://en.wikipedia.org/wiki/OpenDocument
@@ -6004,11 +6006,18 @@ or image itself, if these differ.
60046006

60056007
### Extension: `mark` ###
60066008

6007-
To highlight out a section of text, begin and end it with
6009+
To highlight a section of text, begin and end it with
60086010
with `==`. Thus, for example,
60096011

60106012
This ==is deleted text.==
60116013

6014+
### Extension: `comments` ###
6015+
6016+
To comment out a section of text, begin and end it
6017+
with `%%`. Thus, for example,
6018+
6019+
This %%is a comment.%%
6020+
60126021
### Extension: `attributes` ###
60136022

60146023
Allows attributes to be attached to any inline or block-level
@@ -6155,15 +6164,16 @@ simply skipped (as opposed to being parsed as paragraphs).
61556164

61566165
### Extension: `alerts` ###
61576166

6158-
Supports [GitHub-style Markdown alerts], like
6167+
Supports [GitHub-style Markdown alerts] and [Obsidian callouts], like
61596168

61606169
> [!TIP]
61616170
> Helpful advice for doing things better or more easily.
61626171

6172+
[Obsidian callouts]: https://help.obsidian.md/callouts
61636173
[GitHub-style Markdown alerts]: https://docs.github.com/en/get-started/writing-on-github/getting-started-with-writing-and-formatting-on-github/basic-writing-and-formatting-syntax#alerts
61646174

61656175
Note: This extension currently only works with commonmark:
6166-
`commonmark`, `gfm`, `commonmark_x`.
6176+
`commonmark`, `gfm`, `commonmark_x`, `obsidian`.
61676177

61686178
### Extension: `autolink_bare_uris` ###
61696179

@@ -6213,6 +6223,38 @@ or
62136223

62146224
Oxygen is O~2.
62156225

6226+
### Extension: `wikilink_transclusions` ###
6227+
6228+
Follows [Obsidan-style transclusions] using wikilink syntax to embed one file in another. For example to transclude the file "Title":
6229+
6230+
![[Title]]
6231+
6232+
[Obsidan-style transclusions]: https://help.obsidian.md/embeds
6233+
6234+
### Extension: `wilikink_heading_transclusions` ###
6235+
6236+
Follows the [Obsidan-style heading transclusions] syntax. For example to transclude a heading within the file "Title":
6237+
6238+
![[Title#Heading]]
6239+
6240+
[Obsidan-style heading transclusions]: https://help.obsidian.md/links#Link+to+a+heading+in+a+note
6241+
6242+
### Extension: `wilikink_block_transclusions` ###
6243+
6244+
Follows the [Obsidan-style block transclusions] syntax. For example to transclude block ID ^ref within the file "Title":
6245+
6246+
![[Title#^ref]]
6247+
6248+
[Obsidan-style block transclusions]: https://help.obsidian.md/links#Link+to+a+block+in+a+note
6249+
6250+
### Extension: `block_ids` ###
6251+
6252+
Follows the [Obsidan-style block identifiers] syntax. For example add `^ref` at the end of a paragraph:
6253+
6254+
Text ^ref
6255+
6256+
[Obsidan-style block identifiers]: https://help.obsidian.md/links#Link+to+a+block+in+a+note
6257+
62166258
### Extension: `wikilinks_title_after_pipe` ###
62176259

62186260
Pandoc supports multiple Markdown wikilink syntaxes, regardless of
@@ -6240,6 +6282,7 @@ variants are supported:
62406282
- `markdown_strict` (Markdown.pl)
62416283
- `commonmark` (CommonMark)
62426284
- `gfm` (Github-Flavored Markdown)
6285+
- `obsidian` (Obsidian-Flavored Markdown)
62436286
- `commonmark_x` (CommonMark with many pandoc extensions)
62446287

62456288
To see which extensions are supported for a given format,

src/Text.Pandoc/Parsing.hs

Whitespace-only changes.

src/Text/Pandoc/Extensions.hs

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,10 @@ data Extension =
5757
| Ext_backtick_code_blocks -- ^ GitHub style ``` code blocks
5858
| Ext_blank_before_blockquote -- ^ Require blank line before a blockquote
5959
| Ext_blank_before_header -- ^ Require blank line before a header
60+
| Ext_block_ids -- ^ Block identifiers, used by Obsidian
6061
| Ext_bracketed_spans -- ^ Bracketed spans with attributes
6162
| Ext_citations -- ^ Pandoc/citeproc citations
63+
| Ext_comments -- ^ Percent wrapped %%comments%%
6264
| Ext_definition_lists -- ^ Definition lists as in pandoc, mmd, php
6365
| Ext_east_asian_line_breaks -- ^ Newlines in paragraphs are ignored between
6466
-- East Asian wide characters. Note: this extension
@@ -141,6 +143,9 @@ data Extension =
141143
-- [[target|title]]
142144
| Ext_wikilinks_title_before_pipe -- ^ Support wikilinks of style
143145
-- [[title|target]]
146+
| Ext_wikilink_transclusions -- ^ Wikilink transclusion e.g. ![[title]]
147+
| Ext_wikilink_heading_transclusions -- ^ Wikilink heading transclusion e.g. ![[title#heading]] in Obsidian
148+
| Ext_wikilink_block_transclusions -- ^ Wikilink block transclusions, e.g. ![[title#^id]] in Obsidian
144149
| Ext_xrefs_name -- ^ Use xrefs with names
145150
| Ext_xrefs_number -- ^ Use xrefs with numbers
146151
| Ext_yaml_metadata_block -- ^ YAML metadata block
@@ -405,6 +410,26 @@ getDefaultExtensions "gfm" = extensionsFromList
405410
, Ext_tex_math_gfm
406411
, Ext_alerts
407412
]
413+
getDefaultExtensions "obsidian" = extensionsFromList
414+
[ Ext_alerts
415+
, Ext_autolink_bare_uris
416+
, Ext_block_ids
417+
, Ext_comments
418+
, Ext_footnotes
419+
, Ext_hard_line_breaks
420+
, Ext_mark
421+
, Ext_pipe_tables
422+
, Ext_raw_html
423+
, Ext_rebase_relative_paths
424+
, Ext_strikeout
425+
, Ext_task_lists
426+
, Ext_tex_math_dollars
427+
, Ext_wikilinks_title_after_pipe
428+
, Ext_wikilink_transclusions
429+
, Ext_wikilink_block_transclusions
430+
, Ext_wikilink_heading_transclusions
431+
, Ext_yaml_metadata_block
432+
]
408433
getDefaultExtensions "commonmark" = extensionsFromList
409434
[Ext_raw_html]
410435
getDefaultExtensions "commonmark_x" = extensionsFromList
@@ -525,6 +550,27 @@ getAllExtensions f = universalExtensions <> getAll f
525550
getAll "markdown_mmd" = allMarkdownExtensions
526551
getAll "markdown_github" = allMarkdownExtensions
527552
getAll "markdown" = allMarkdownExtensions
553+
getAll "obsidian" = allMarkdownExtensions <> extensionsFromList
554+
[ Ext_ascii_identifiers
555+
, Ext_alerts
556+
, Ext_autolink_bare_uris
557+
, Ext_block_ids
558+
, Ext_comments
559+
, Ext_footnotes
560+
, Ext_hard_line_breaks
561+
, Ext_mark
562+
, Ext_pipe_tables
563+
, Ext_raw_html
564+
, Ext_rebase_relative_paths
565+
, Ext_strikeout
566+
, Ext_task_lists
567+
, Ext_tex_math_dollars
568+
, Ext_wikilink_block_transclusions
569+
, Ext_wikilink_heading_transclusions
570+
, Ext_wikilink_transclusions
571+
, Ext_wikilinks_title_after_pipe
572+
, Ext_yaml_metadata_block
573+
]
528574
getAll "ipynb" = allMarkdownExtensions <> extensionsFromList
529575
[ Ext_raw_markdown ]
530576
getAll "docx" = autoIdExtensions <> extensionsFromList

src/Text/Pandoc/Parsing/State.hs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ data ParserState = ParserState
7777
, stateContainers :: [Text] -- ^ parent include files
7878
, stateLogMessages :: [LogMessage] -- ^ log messages
7979
, stateMarkdownAttribute :: Bool -- ^ True if in markdown=1 context
80+
, stateLastBlockId :: Maybe Text
8081
}
8182

8283
instance Default ParserState where
@@ -166,6 +167,7 @@ defaultParserState = ParserState
166167
, stateContainers = []
167168
, stateLogMessages = []
168169
, stateMarkdownAttribute = False
170+
, stateLastBlockId = Nothing
169171
}
170172

171173
type NoteTable = [(Text, Text)]

src/Text/Pandoc/Readers.hs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@ readers = [("native" , TextReader readNative)
141141
,("creole" , TextReader readCreole)
142142
,("dokuwiki" , TextReader readDokuWiki)
143143
,("gfm" , TextReader readCommonMark)
144+
,("obsidian" , TextReader readMarkdown)
144145
,("rst" , TextReader readRST)
145146
,("mediawiki" , TextReader readMediaWiki)
146147
,("vimwiki" , TextReader readVimwiki)

0 commit comments

Comments
 (0)