Skip to content

Commit

Permalink
Markdown reader: fix blindspot with superscript in links.
Browse files Browse the repository at this point in the history
Previously `[^super^](#ref)` wasn't parsed as a link, due to
code that was meant to prevent footnote markers from being
recognized as reference links.  This commit tightens up that
code to avoid this bad effect.

We have also added a new restriction on footnote labels: they
cannot contain the characters `^`, `[`, or `]`. Though this is
technically a breaking change, we suspect that the impact will
be minimal, as it's very unlikely people would be using these
characters in their note labels.

Closes #8981.
  • Loading branch information
jgm committed Oct 20, 2023
1 parent 0fdac49 commit 5e66811
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 11 deletions.
6 changes: 3 additions & 3 deletions MANUAL.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5509,9 +5509,9 @@ Pandoc's Markdown allows footnotes, using the following syntax:
isn't indented.

The identifiers in footnote references may not contain spaces, tabs,
or newlines. These identifiers are used only to correlate the
footnote reference with the note itself; in the output, footnotes
will be numbered sequentially.
newlines, or the characters `^`, `[`, or `]`. These identifiers
are used only to correlate the footnote reference with the note
itself; in the output, footnotes will be numbered sequentially.

The footnotes themselves need not be placed at the end of the
document. They may appear anywhere except inside other block elements
Expand Down
12 changes: 4 additions & 8 deletions src/Text/Pandoc/Readers/Markdown.hs
Original file line number Diff line number Diff line change
Expand Up @@ -142,12 +142,6 @@ isHruleChar _ = False
setextHChars :: [Char]
setextHChars = "=-"

isBlank :: Char -> Bool
isBlank ' ' = True
isBlank '\t' = True
isBlank '\n' = True
isBlank _ = False

--
-- auxiliary functions
--
Expand Down Expand Up @@ -416,7 +410,9 @@ abbrevKey = do
return $ return mempty

noteMarker :: PandocMonad m => MarkdownParser m Text
noteMarker = string "[^" >> many1TillChar (satisfy $ not . isBlank) (char ']')
noteMarker = string "[^" >>
many1TillChar (satisfy (`notElem` ['\r','\n','\t',' ','^','[',']']))
(char ']')

rawLine :: PandocMonad m => MarkdownParser m Text
rawLine = try $ do
Expand Down Expand Up @@ -1815,7 +1811,7 @@ endline = try $ do
-- a reference label for a link
reference :: PandocMonad m => MarkdownParser m (F Inlines, Text)
reference = do
guardDisabled Ext_footnotes <|> notFollowedBy' (string "[^")
guardDisabled Ext_footnotes <|> notFollowedBy' noteMarker
withRaw $ trimInlinesF <$> inlinesInBalancedBrackets

parenthesizedChars :: PandocMonad m => MarkdownParser m Text
Expand Down
6 changes: 6 additions & 0 deletions test/command/8981.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
```
% pandoc --wrap=none
consectetur [^\[link\]^](#ref "Title")
^D
<p>consectetur <a href="#ref" title="Title"><sup>[link]</sup></a></p>
```

0 comments on commit 5e66811

Please sign in to comment.