git.iko.soy/typeable/pandoc
on master help sign in
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.

commit48c88d566d19683a7d5b63f88c8b4487234e3712 authorJohn MacFarlane <jgm@berkeley.edu> dateMon 20 Mar 2017, 21:51 (10 years ago) parent2d94d48
4 files changed+23
MANUAL.txt+6 src/Text/Pandoc/Extensions.hs+3 src/Text/Pandoc/Readers/Markdown.hs+1 test/command/3512.md+13
MANUAL.txt+6
@@ -1634,6 +1634,12 @@ wrapping). Consider, for example:
16341634 I like several of their flavors of ice cream:
16351635 #22, for example, and #5.
16361636
1637+#### Extension: `space_in_atx_header` ####
1638+
1639+Many Markdown implementations do not require a space between the
1640+opening `#`s of an ATX header and the header text, so that
1641+`#5 bolt` and `#hashtag` count as headers. With this extension,
1642+pandoc does require the space.
16371643
16381644### Header identifiers ###
16391645
src/Text/Pandoc/Extensions.hs+3
@@ -112,6 +112,7 @@ data Extension =
112112 | Ext_intraword_underscores -- ^ Treat underscore inside word as literal
113113 | Ext_blank_before_blockquote -- ^ Require blank line before a blockquote
114114 | Ext_blank_before_header -- ^ Require blank line before a header
115+ | Ext_space_in_atx_header -- ^ Require space between # and header text
115116 | Ext_strikeout -- ^ Strikeout using ~~this~~ syntax
116117 | Ext_superscript -- ^ Superscript using ^this^ syntax
117118 | Ext_subscript -- ^ Subscript using ~this~ syntax
@@ -168,6 +169,7 @@ pandocExtensions = extensionsFromList
168169 , Ext_intraword_underscores
169170 , Ext_blank_before_blockquote
170171 , Ext_blank_before_header
172+ , Ext_space_in_atx_header
171173 , Ext_strikeout
172174 , Ext_superscript
173175 , Ext_subscript
@@ -223,6 +225,7 @@ githubMarkdownExtensions = extensionsFromList
223225 , Ext_ascii_identifiers
224226 , Ext_backtick_code_blocks
225227 , Ext_autolink_bare_uris
228+ , Ext_space_in_atx_header
226229 , Ext_intraword_underscores
227230 , Ext_strikeout
228231 , Ext_hard_line_breaks
src/Text/Pandoc/Readers/Markdown.hs+1
@@ -534,6 +534,7 @@ atxHeader = try $ do
534534 level <- atxChar >>= many1 . char >>= return . length
535535 notFollowedBy $ guardEnabled Ext_fancy_lists >>
536536 (char '.' <|> char ')') -- this would be a list
537+ guardDisabled Ext_space_in_atx_header <|> notFollowedBy nonspaceChar
537538 skipSpaces
538539 (text, raw) <- withRaw $
539540 trimInlinesF . mconcat <$> many (notFollowedBy atxClosing >> inline)
test/command/3512.mdnew file+13
@@ -0,0 +1,13 @@
1+```
2+% pandoc -f markdown-auto_identifiers
3+#hi
4+^D
5+<p>#hi</p>
6+```
7+
8+```
9+% pandoc -f markdown-auto_identifiers-space_in_atx_header
10+#hi
11+^D
12+<h1>hi</h1>
13+```