summaryrefslogtreecommitdiff
path: root/src/Text
diff options
context:
space:
mode:
authorJohn MacFarlane <jgm@berkeley.edu>2022-07-28 11:15:25 -0700
committerJohn MacFarlane <jgm@berkeley.edu>2022-07-28 11:28:02 -0700
commit5c3423f2e2b441f9fe630538906b5fc1436e04f3 (patch)
tree0723ae293d3c21593a0be94a3fd10e4cc385ffd0 /src/Text
parentaaf69044b19841854000fe1a27e85279dfa5b750 (diff)
DokuWiki reader: support latex plugin and math.
The `tex_math_dollars` extension is now supported for `dokuwiki` (but off by default). Content inside `<latex>...</latex>` is parsed as raw LaTeX inline, and inside `<LATEX>..</LATEX>` as raw LaTeX block. In addition, this commit changes the behavior of `<php>...</php>` so that instead of producing a code block, it produces raw HTML with `<?php ... ?>`. Closes #8178.
Diffstat (limited to 'src/Text')
-rw-r--r--src/Text/Pandoc/Extensions.hs4
-rw-r--r--src/Text/Pandoc/Readers/DokuWiki.hs52
2 files changed, 35 insertions, 21 deletions
diff --git a/src/Text/Pandoc/Extensions.hs b/src/Text/Pandoc/Extensions.hs
index 1579dfaeb..cc4f0c730 100644
--- a/src/Text/Pandoc/Extensions.hs
+++ b/src/Text/Pandoc/Extensions.hs
@@ -592,7 +592,9 @@ getAllExtensions f = universalExtensions <> getAll f
extensionsFromList
[ Ext_smart ]
getAll "vimwiki" = autoIdExtensions
- getAll "dokuwiki" = autoIdExtensions
+ getAll "dokuwiki" = autoIdExtensions <>
+ extensionsFromList
+ [ Ext_tex_math_dollars ]
getAll "tikiwiki" = autoIdExtensions
getAll "rst" = autoIdExtensions <>
extensionsFromList
diff --git a/src/Text/Pandoc/Readers/DokuWiki.hs b/src/Text/Pandoc/Readers/DokuWiki.hs
index 82df2784e..d1b673611 100644
--- a/src/Text/Pandoc/Readers/DokuWiki.hs
+++ b/src/Text/Pandoc/Readers/DokuWiki.hs
@@ -117,8 +117,8 @@ inline'' = br
<|> footnote
<|> inlineCode
<|> inlineFile
- <|> inlineHtml
- <|> inlinePhp
+ <|> inlineRaw
+ <|> math
<|> autoLink
<|> autoEmail
<|> notoc
@@ -209,11 +209,22 @@ inlineCode = codeTag B.codeWith "code"
inlineFile :: PandocMonad m => DWParser m B.Inlines
inlineFile = codeTag B.codeWith "file"
-inlineHtml :: PandocMonad m => DWParser m B.Inlines
-inlineHtml = try $ B.rawInline "html" <$ string "<html>" <*> manyTillChar anyChar (try $ string "</html>")
-
-inlinePhp :: PandocMonad m => DWParser m B.Inlines
-inlinePhp = try $ B.codeWith ("", ["php"], []) <$ string "<php>" <*> manyTillChar anyChar (try $ string "</php>")
+inlineRaw :: PandocMonad m => DWParser m B.Inlines
+inlineRaw = try $ do
+ char '<'
+ fmt <- oneOfStrings ["html", "php", "latex"]
+ -- LaTeX via https://www.dokuwiki.org/plugin:latex
+ char '>'
+ contents <- manyTillChar anyChar
+ (try $ string "</" *> string (T.unpack fmt) *> char '>')
+ return $
+ case T.toLower fmt of
+ "php" -> B.rawInline "html" $ "<?php " <> contents <> " ?>"
+ f -> B.rawInline f contents
+
+-- see https://www.dokuwiki.org/plugin:latex
+math :: PandocMonad m => DWParser m B.Inlines
+math = (B.displayMath <$> mathDisplay) <|> (B.math <$> mathInline)
makeLink :: (Text, Text) -> B.Inlines
makeLink (text, url) = B.link url "" $ B.str text
@@ -410,8 +421,7 @@ blockElements = horizontalLine
<|> quote
<|> blockCode
<|> blockFile
- <|> blockHtml
- <|> blockPhp
+ <|> blockRaw
<|> table
horizontalLine :: PandocMonad m => DWParser m B.Blocks
@@ -462,17 +472,19 @@ quote = try $ nestedQuote 0
quoteContinuation level = mconcat <$> many (try $ prefix level *> contents level)
nestedQuote level = B.blockQuote <$ char '>' <*> quoteContents (level + 1 :: Int)
-blockHtml :: PandocMonad m => DWParser m B.Blocks
-blockHtml = try $ B.rawBlock "html"
- <$ string "<HTML>"
- <* optional (manyTill spaceChar eol)
- <*> manyTillChar anyChar (try $ string "</HTML>")
-
-blockPhp :: PandocMonad m => DWParser m B.Blocks
-blockPhp = try $ B.codeBlockWith ("", ["php"], [])
- <$ string "<PHP>"
- <* optional (manyTill spaceChar eol)
- <*> manyTillChar anyChar (try $ string "</PHP>")
+blockRaw :: PandocMonad m => DWParser m B.Blocks
+blockRaw = try $ do
+ char '<'
+ fmt <- oneOfStrings ["HTML", "PHP", "LATEX"]
+ -- LaTeX via https://www.dokuwiki.org/plugin:latex
+ char '>'
+ optional (manyTill spaceChar eol)
+ contents <- manyTillChar anyChar
+ (try $ string "</" *> string (T.unpack fmt) *> char '>')
+ return $
+ case T.toLower fmt of
+ "php" -> B.rawBlock "html" $ "<?php " <> contents <> " ?>"
+ f -> B.rawBlock f contents
table :: PandocMonad m => DWParser m B.Blocks
table = do