aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJohn MacFarlane <[email protected]>2024-02-13 22:20:03 -0800
committerJohn MacFarlane <[email protected]>2024-02-13 22:20:03 -0800
commita5b691a77e6cf250b1e82a5e6c5a4514e5fb1b6e (patch)
tree56a579d12e6c897205be166dad7b7ddeb1abde8f /src
parent621d694e2cbd567e295a80e0941c62e625838ffb (diff)
Markdown reader: fix wikilinks extension to allow newlines in titles.
Closes #9454.
Diffstat (limited to 'src')
-rw-r--r--src/Text/Pandoc/Readers/Markdown.hs27
1 files changed, 14 insertions, 13 deletions
diff --git a/src/Text/Pandoc/Readers/Markdown.hs b/src/Text/Pandoc/Readers/Markdown.hs
index 9f45154ed..31d1b5198 100644
--- a/src/Text/Pandoc/Readers/Markdown.hs
+++ b/src/Text/Pandoc/Readers/Markdown.hs
@@ -1843,19 +1843,20 @@ linkTitle = quotedTitle '"' <|> quotedTitle '\''
wikilink :: PandocMonad m
=> (Attr -> Text -> Text -> Inlines -> Inlines)
-> MarkdownParser m (F Inlines)
-wikilink constructor =
- (guardEnabled Ext_wikilinks_title_after_pipe *> wikilink' swap) <|>
- (guardEnabled Ext_wikilinks_title_before_pipe *> wikilink' id)
- where
- swap (a, b) = (b, a)
- wikilink' order = try $ do
- string "[["
- notFollowedBy' (char '[')
- raw <- many1TillChar (noneOf "\n\r\f\t") (try $ string "]]")
- let (title, url) = case T.break (== '|') raw of
- (before, "") -> (before, before)
- (before, after) -> order (before, T.drop 1 after)
- return . pure . constructor nullAttr url "wikilink" $ B.str title
+wikilink constructor = do
+ titleAfter <-
+ (True <$ guardEnabled Ext_wikilinks_title_after_pipe) <|>
+ (False <$ guardEnabled Ext_wikilinks_title_before_pipe)
+ string "[[" *> notFollowedBy' (char '[')
+ raw <- many1TillChar anyChar (try $ string "]]")
+ let (title, url) = case T.break (== '|') raw of
+ (before, "") -> (before, before)
+ (before, after)
+ | titleAfter -> (T.drop 1 after, before)
+ | otherwise -> (before, T.drop 1 after)
+ guard $ T.all (`notElem` ['\n','\r','\f','\t']) url
+ return . pure . constructor nullAttr url "wikilink" $
+ B.text $ fromEntities title
link :: PandocMonad m => MarkdownParser m (F Inlines)
link = try $ do