From 5e668118751b50aaf7f6ab675dd5dc628ced30bc Mon Sep 17 00:00:00 2001 From: John MacFarlane Date: Fri, 20 Oct 2023 10:27:49 -0700 Subject: 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. --- src/Text/Pandoc/Readers/Markdown.hs | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) (limited to 'src/Text') 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 -- cgit v1.2.3