summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn MacFarlane <jgm@berkeley.edu>2023-10-22 10:59:07 -0700
committerJohn MacFarlane <jgm@berkeley.edu>2023-10-22 10:59:07 -0700
commitfbf9194e345f4e0fae287b3e32562df855c2224e (patch)
treecee28e20b71d3f5fdaf840646e8789747c8dc69f
parentad1a745f725e3fe12d02339b0caf1af6e8b4924f (diff)
DokuWiki reader: parse `<code>` and `<file>` as block-level code.
Previously we treated them as inline code in some contexts, but that is not how DokuWiki works. Closes #9154.
-rw-r--r--src/Text/Pandoc/Readers/DokuWiki.hs26
-rw-r--r--test/Tests/Readers/DokuWiki.hs7
2 files changed, 13 insertions, 20 deletions
diff --git a/src/Text/Pandoc/Readers/DokuWiki.hs b/src/Text/Pandoc/Readers/DokuWiki.hs
index 77213a111..26a17c3ff 100644
--- a/src/Text/Pandoc/Readers/DokuWiki.hs
+++ b/src/Text/Pandoc/Readers/DokuWiki.hs
@@ -105,8 +105,6 @@ inline'' = br
<|> superscript
<|> deleted
<|> footnote
- <|> inlineCode
- <|> inlineFile
<|> inlineRaw
<|> math
<|> autoLink
@@ -193,12 +191,6 @@ deleted = try $ B.strikeout <$> between (string "<del>") (try $ string "</del>")
footnote :: PandocMonad m => DWParser m B.Inlines
footnote = try $ B.note . B.para <$> between (string "((") (try $ string "))") nestedInlines
-inlineCode :: PandocMonad m => DWParser m B.Inlines
-inlineCode = codeTag B.codeWith "code"
-
-inlineFile :: PandocMonad m => DWParser m B.Inlines
-inlineFile = codeTag B.codeWith "file"
-
inlineRaw :: PandocMonad m => DWParser m B.Inlines
inlineRaw = try $ do
char '<'
@@ -247,7 +239,7 @@ str :: PandocMonad m => DWParser m B.Inlines
str = B.str <$> (many1Char alphaNum <|> characterReference)
symbol :: PandocMonad m => DWParser m B.Inlines
-symbol = B.str <$> countChar 1 nonspaceChar
+symbol = B.str <$> (notFollowedBy' blockCode *> countChar 1 nonspaceChar)
link :: PandocMonad m => DWParser m B.Inlines
link = try $ do
@@ -414,7 +406,6 @@ blockElements = horizontalLine
<|> indentedCode
<|> quote
<|> blockCode
- <|> blockFile
<|> blockRaw
<|> table
@@ -448,8 +439,10 @@ parseList prefix marker =
many1 ((<>) <$> item <*> fmap mconcat (many continuation))
where
continuation = try $ list (" " <> prefix)
- item = try $ textStr prefix *> char marker *> char ' ' *> itemContents
- itemContents = B.plain . mconcat <$> many1Till inline' eol
+ item = try $ textStr prefix *> char marker *> char ' ' *>
+ (mconcat <$> many1 itemContents <* eol)
+ itemContents = (B.plain . mconcat <$> many1 inline') <|>
+ blockCode
indentedCode :: PandocMonad m => DWParser m B.Blocks
indentedCode = try $ B.codeBlock . T.unlines <$> many1 indentedLine
@@ -533,10 +526,8 @@ tableCell = try $ (second (B.plain . B.trimInlines . mconcat)) <$> cellContent
blockCode :: PandocMonad m => DWParser m B.Blocks
-blockCode = codeTag B.codeBlockWith "code"
-
-blockFile :: PandocMonad m => DWParser m B.Blocks
-blockFile = codeTag B.codeBlockWith "file"
+blockCode = codeTag B.codeBlockWith "code" <|>
+ codeTag B.codeBlockWith "file"
para :: PandocMonad m => DWParser m B.Blocks
para = result . mconcat <$> many1Till inline endOfParaElement
@@ -544,7 +535,8 @@ para = result . mconcat <$> many1Till inline endOfParaElement
endOfParaElement = lookAhead $ endOfInput <|> endOfPara <|> newBlockElement
endOfInput = try $ skipMany blankline >> skipSpaces >> eof
endOfPara = try $ blankline >> skipMany1 blankline
- newBlockElement = try $ blankline >> void blockElements
+ newBlockElement = try (blankline >> void blockElements)
+ <|> lookAhead (void blockCode)
result content = if F.all (==Space) content
then mempty
else B.para $ B.trimInlines content
diff --git a/test/Tests/Readers/DokuWiki.hs b/test/Tests/Readers/DokuWiki.hs
index c0363db31..2b955c2f4 100644
--- a/test/Tests/Readers/DokuWiki.hs
+++ b/test/Tests/Readers/DokuWiki.hs
@@ -71,10 +71,11 @@ tests = [ testGroup "inlines"
para (strikeout "deleted")
, "Inline code" =:
"foo <code java>public static void main</code> bar" =?>
- para (text "foo " <> codeWith ("", ["java"], []) "public static void main" <> text " bar")
+ para (text "foo") <> codeBlockWith ("", ["java"], []) "public static void main"
+ <> para (text "bar")
, "Inline file" =:
"foo <file></code></file> bar" =?>
- para (text "foo " <> code "</code>" <> text " bar")
+ para (text "foo") <> codeBlock "</code>" <> para (text "bar")
, "Inline HTML" =:
"<html>\nThis is some <span style=\"color:red;font-size:150%;\">inline HTML</span>\n</html>" =?>
para (rawInline "html" "\nThis is some <span style=\"color:red;font-size:150%;\">inline HTML</span>\n")
@@ -245,7 +246,7 @@ tests = [ testGroup "inlines"
] =?>
orderedList [ plain "first item"
, plain ("second item with linebreak" <> linebreak <> " second line")
- , plain ("third item with code: " <> code "some code\ncomes here\n")
+ , plain "third item with code: " <> codeBlock "some code\ncomes here\n"
, plain "fourth item"
]
]