Skip to content

Commit

Permalink
Do not parse hard line breaks in fenced codeblock info
Browse files Browse the repository at this point in the history
This change makes commonmark-hs act the same as most other
CommonMark implementations I've tried (markdown-it, pulldown-cmark,
goldmark, commonmark.js, GFM).
  • Loading branch information
notriddle committed Oct 26, 2023
1 parent cf945af commit d0d7762
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
4 changes: 2 additions & 2 deletions commonmark/src/Commonmark/Blocks.hs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ where
import Commonmark.Tag
import Commonmark.TokParsers
import Commonmark.ReferenceMap
import Commonmark.Inlines (pEscaped, pLinkDestination,
import Commonmark.Inlines (pEscapedSymbol, pLinkDestination,
pLinkLabel, pLinkTitle)
import Commonmark.Entity (unEntity)
import Commonmark.Tokens
Expand Down Expand Up @@ -1042,7 +1042,7 @@ fencedCodeSpec = BlockSpec
guard $ fencelength >= 3
skipWhile (hasType Spaces)
let infoTok = noneOfToks (LineEnd : [Symbol '`' | c == '`'])
info <- T.strip . unEntity <$> many (pEscaped <|> infoTok)
info <- T.strip . unEntity <$> many (pEscapedSymbol <|> infoTok)
lookAhead $ void lineEnd <|> eof

let infotoks = tokenize "info string" info
Expand Down
7 changes: 7 additions & 0 deletions commonmark/src/Commonmark/Inlines.hs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ module Commonmark.Inlines
, pLinkDestination
, pLinkTitle
, pEscaped
, pEscapedSymbol
, processEmphasis
, processBrackets
, pBacktickSpan
Expand Down Expand Up @@ -937,6 +938,12 @@ pEscaped = do
bs <- symbol '\\'
option bs $ satisfyTok asciiSymbol <|> lineEnd

-- parses backslash + punctuation, but not backslashed newline
pEscapedSymbol :: Monad m => ParsecT [Tok] s m Tok
pEscapedSymbol = do
bs <- symbol '\\'
option bs $ satisfyTok asciiSymbol

asciiSymbol :: Tok -> Bool
asciiSymbol (Tok (Symbol c) _ _) = isAscii c
asciiSymbol _ = False
Expand Down
9 changes: 9 additions & 0 deletions commonmark/test/regression.md
Original file line number Diff line number Diff line change
Expand Up @@ -210,3 +210,12 @@ Issue #114.
.
<p>*.*̀.</p>
````````````````````````````````

Issue #115.
```````````````````````````````` example
~~~\
x
.
<pre><code class="language-\">x
</code></pre>
````````````````````````````````
Expand Down

0 comments on commit d0d7762

Please sign in to comment.