diff options
author | John MacFarlane <jgm@berkeley.edu> | 2017-03-20 21:51:29 +0100 |
---|---|---|
committer | John MacFarlane <jgm@berkeley.edu> | 2017-03-20 21:55:30 +0100 |
commit | 48c88d566d19683a7d5b63f88c8b4487234e3712 (patch) | |
tree | 1ae336f35247b25c5b79b1a08b937e2341f93f18 | |
parent | 2d94d4833290692f1673b83a8068ac466cc77619 (diff) | |
download | pandoc-48c88d566d19683a7d5b63f88c8b4487234e3712.tar.gz |
Add `space_in_atx_header` extension.
This is enabled by default in pandoc and GitHub markdown but not the
other flavors.
This requirse a space between the opening #'s and the header
text in ATX headers (as CommonMark does but many other implementations
do not). This is desirable to avoid falsely capturing things ilke
#hashtag
or
#5
Closes #3512.
-rw-r--r-- | MANUAL.txt | 6 | ||||
-rw-r--r-- | src/Text/Pandoc/Extensions.hs | 3 | ||||
-rw-r--r-- | src/Text/Pandoc/Readers/Markdown.hs | 1 | ||||
-rw-r--r-- | test/command/3512.md | 13 |
4 files changed, 23 insertions, 0 deletions
diff --git a/MANUAL.txt b/MANUAL.txt index 12e3b2f9e..520e8f5d5 100644 --- a/MANUAL.txt +++ b/MANUAL.txt @@ -1634,6 +1634,12 @@ wrapping). Consider, for example: I like several of their flavors of ice cream: #22, for example, and #5. +#### Extension: `space_in_atx_header` #### + +Many Markdown implementations do not require a space between the +opening `#`s of an ATX header and the header text, so that +`#5 bolt` and `#hashtag` count as headers. With this extension, +pandoc does require the space. ### Header identifiers ### diff --git a/src/Text/Pandoc/Extensions.hs b/src/Text/Pandoc/Extensions.hs index b543d489f..54f38f4a0 100644 --- a/src/Text/Pandoc/Extensions.hs +++ b/src/Text/Pandoc/Extensions.hs @@ -112,6 +112,7 @@ data Extension = | Ext_intraword_underscores -- ^ Treat underscore inside word as literal | Ext_blank_before_blockquote -- ^ Require blank line before a blockquote | Ext_blank_before_header -- ^ Require blank line before a header + | Ext_space_in_atx_header -- ^ Require space between # and header text | Ext_strikeout -- ^ Strikeout using ~~this~~ syntax | Ext_superscript -- ^ Superscript using ^this^ syntax | Ext_subscript -- ^ Subscript using ~this~ syntax @@ -168,6 +169,7 @@ pandocExtensions = extensionsFromList , Ext_intraword_underscores , Ext_blank_before_blockquote , Ext_blank_before_header + , Ext_space_in_atx_header , Ext_strikeout , Ext_superscript , Ext_subscript @@ -223,6 +225,7 @@ githubMarkdownExtensions = extensionsFromList , Ext_ascii_identifiers , Ext_backtick_code_blocks , Ext_autolink_bare_uris + , Ext_space_in_atx_header , Ext_intraword_underscores , Ext_strikeout , Ext_hard_line_breaks diff --git a/src/Text/Pandoc/Readers/Markdown.hs b/src/Text/Pandoc/Readers/Markdown.hs index 169872391..0cc10c1d4 100644 --- a/src/Text/Pandoc/Readers/Markdown.hs +++ b/src/Text/Pandoc/Readers/Markdown.hs @@ -534,6 +534,7 @@ atxHeader = try $ do level <- atxChar >>= many1 . char >>= return . length notFollowedBy $ guardEnabled Ext_fancy_lists >> (char '.' <|> char ')') -- this would be a list + guardDisabled Ext_space_in_atx_header <|> notFollowedBy nonspaceChar skipSpaces (text, raw) <- withRaw $ trimInlinesF . mconcat <$> many (notFollowedBy atxClosing >> inline) diff --git a/test/command/3512.md b/test/command/3512.md new file mode 100644 index 000000000..cf8c72e58 --- /dev/null +++ b/test/command/3512.md @@ -0,0 +1,13 @@ +``` +% pandoc -f markdown-auto_identifiers +#hi +^D +<p>#hi</p> +``` + +``` +% pandoc -f markdown-auto_identifiers-space_in_atx_header +#hi +^D +<h1>hi</h1> +``` |