summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn MacFarlane <jgm@berkeley.edu>2023-10-20 10:27:49 -0700
committerJohn MacFarlane <jgm@berkeley.edu>2023-10-20 10:27:49 -0700
commit5e668118751b50aaf7f6ab675dd5dc628ced30bc (patch)
tree919f081121f3f17be974234f71f59fd900fc6b88
parent0fdac4984b61de9de07f730ea071ee2bb9f1076c (diff)
Markdown reader: fix blindspot with superscript in links.
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.
-rw-r--r--MANUAL.txt6
-rw-r--r--src/Text/Pandoc/Readers/Markdown.hs12
-rw-r--r--test/command/8981.md6
3 files changed, 13 insertions, 11 deletions
diff --git a/MANUAL.txt b/MANUAL.txt
index d3be3b69c..b56121d95 100644
--- a/MANUAL.txt
+++ b/MANUAL.txt
@@ -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
diff --git a/src/Text/Pandoc/Readers/Markdown.hs b/src/Text/Pandoc/Readers/Markdown.hs
index 731ca07a6..402893897 100644
--- a/src/Text/Pandoc/Readers/Markdown.hs
+++ b/src/Text/Pandoc/Readers/Markdown.hs
@@ -142,12 +142,6 @@ isHruleChar _ = False
setextHChars :: [Char]
setextHChars = "=-"
-isBlank :: Char -> Bool
-isBlank ' ' = True
-isBlank '\t' = True
-isBlank '\n' = True
-isBlank _ = False
-
--
-- auxiliary functions
--
@@ -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
@@ -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
diff --git a/test/command/8981.md b/test/command/8981.md
new file mode 100644
index 000000000..00ba6d231
--- /dev/null
+++ b/test/command/8981.md
@@ -0,0 +1,6 @@
+```
+% pandoc --wrap=none
+consectetur [^\[link\]^](#ref "Title")
+^D
+<p>consectetur <a href="#ref" title="Title"><sup>[link]</sup></a></p>
+```