Skip to content

Commit

Permalink
Parse [^ ] as a link
Browse files Browse the repository at this point in the history
This matches the behavior of GitHub, etc more closely.
  • Loading branch information
notriddle authored and jgm committed Oct 30, 2023
1 parent 7f2d008 commit 6805f80
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
5 changes: 3 additions & 2 deletions commonmark-extensions/src/Commonmark/Extensions/Footnote.hs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import Data.Maybe (fromMaybe, mapMaybe)
import Data.Dynamic
import Data.Tree
import Text.Parsec
import Data.Text (Text, empty)
import Data.Text (Text)
import qualified Data.Text as T
import qualified Data.Map as M

Expand Down Expand Up @@ -103,7 +103,8 @@ pFootnoteLabel :: Monad m => ParsecT [Tok] u m Text
pFootnoteLabel = try $ do
lab <- pLinkLabel
case T.uncons lab of
Just ('^', t') | t' /= Data.Text.empty -> return $! t'
Just ('^', t') | T.any (\x -> x /= ' ' && x /= '\t' && x /= '\r' && x /= '\n') t'
-> return $! t'
_ -> mzero

pFootnoteRef :: (Monad m, Typeable m, Typeable a,
Expand Down
20 changes: 17 additions & 3 deletions commonmark-extensions/test/footnotes.md
Original file line number Diff line number Diff line change
Expand Up @@ -135,12 +135,26 @@ Footnote containing a list[^list]
</section>
````````````````````````````````

Footnote labels cannot be empty.
Footnote labels cannot be empty, or composed only of whitespace.

```````````````````````````````` example
Test [^] link
Test [^] link [^ ]
[^]: https://haskell.org
.
<p>Test <a href="https://haskell.org">^</a> link</p>
<p>Test <a href="https://haskell.org">^</a> link <a href="https://haskell.org">^ </a></p>
````````````````````````````````

```````````````````````````````` example
[^]: not a footnote
[^ ]: not a footnote
[^
]: not a footnote
.
<p>[^]: not a footnote</p>
<p>[^ ]: not a footnote</p>
<p>[^
]: not a footnote</p>
````````````````````````````````

0 comments on commit 6805f80

Please sign in to comment.