aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn MacFarlane <[email protected]>2025-09-16 11:27:47 +0200
committerJohn MacFarlane <[email protected]>2025-09-16 12:46:25 +0200
commitc3a5513eedf4fbfb135419b2ffa85c81f6521e2b (patch)
treeb4811b8fae07a147e4458b49572920d7e08c9899
parenta0cfb3fd31bc3729266cc3a7aaac1416df183445 (diff)
Markdown reader: refactor out litBetween.
-rw-r--r--src/Text/Pandoc/Readers/Markdown.hs13
1 files changed, 7 insertions, 6 deletions
diff --git a/src/Text/Pandoc/Readers/Markdown.hs b/src/Text/Pandoc/Readers/Markdown.hs
index f6c05cf33..4121240d8 100644
--- a/src/Text/Pandoc/Readers/Markdown.hs
+++ b/src/Text/Pandoc/Readers/Markdown.hs
@@ -190,6 +190,11 @@ litChar = T.singleton <$> escapedChar'
<|> T.singleton <$> noneOf "\n"
<|> try (newline >> notFollowedBy blankline >> return " ")
+litBetween :: PandocMonad m => Char -> Char -> MarkdownParser m Text
+litBetween op cl = try $ do
+ char op
+ mconcat <$> (manyTill litChar (char cl))
+
-- | Parse a sequence of elements between square brackets,
-- including between balanced pairs of square brackets.
-- Skip brackets in standard inline escapes, code, raw HTML or LaTeX.
@@ -356,11 +361,9 @@ referenceKey = try $ do
try (spnl <* keyValAttr)
notFollowedBy' (() <$ reference)
mconcat <$> many1 (notFollowedBy space *> litChar)
- let betweenAngles = try $ char '<' >>
- mconcat <$> (manyTill litChar (char '>'))
rebase <- option False (True <$ guardEnabled Ext_rebase_relative_paths)
src <- (if rebase then rebasePath pos else id) <$>
- (try betweenAngles <|> sourceURL)
+ (try (litBetween '<' '>') <|> sourceURL)
tit <- option "" referenceTitle
attr <- option nullAttr $ try $
do guardEnabled Ext_link_attributes
@@ -1804,9 +1807,7 @@ source = do
<|> (notFollowedBy (oneOf " )") >> litChar)
<|> try (many1Char spaceChar <* notFollowedBy (oneOf "\"')"))
let sourceURL = T.unwords . T.words . T.concat <$> many urlChunk
- let betweenAngles = try $
- char '<' >> mconcat <$> (manyTill litChar (char '>'))
- src <- try betweenAngles <|> try base64DataURI <|> sourceURL
+ src <- try (litBetween '<' '>') <|> try base64DataURI <|> sourceURL
tit <- option "" linkTitle'
skipSpaces
char ')'