Skip to content

Commit

Permalink
Add space_in_atx_header extension.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
jgm committed Mar 20, 2017
1 parent 2d94d48 commit 48c88d5
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 0 deletions.
6 changes: 6 additions & 0 deletions MANUAL.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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 ###

Expand Down
3 changes: 3 additions & 0 deletions src/Text/Pandoc/Extensions.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions src/Text/Pandoc/Readers/Markdown.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
13 changes: 13 additions & 0 deletions test/command/3512.md
Original file line number Diff line number Diff line change
@@ -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>
```

0 comments on commit 48c88d5

Please sign in to comment.