diff options
author | John MacFarlane <fiddlosopher@gmail.com> | 2013-09-07 22:43:56 -0700 |
---|---|---|
committer | John MacFarlane <fiddlosopher@gmail.com> | 2013-09-07 22:43:56 -0700 |
commit | 2c13b6f6dc4f55b76861991dea318e3566cec9a2 (patch) | |
tree | 75085c2cc3ced36eca8602311e951cfa268c42e0 /src/Text/Pandoc | |
parent | 5afd373ae45f525ff1eff5e54c1850fe2c614b4b (diff) | |
download | pandoc-2c13b6f6dc4f55b76861991dea318e3566cec9a2.tar.gz |
MedaWiki reader: Implement some mathjax extensions.
* `:<math>` for display math
* `\(..\)` for inline math
* `\[..\]` for display math
We omit the `$` forms as the heuristics are harder.
Diffstat (limited to 'src/Text/Pandoc')
-rw-r--r-- | src/Text/Pandoc/Readers/MediaWiki.hs | 19 |
1 files changed, 15 insertions, 4 deletions
diff --git a/src/Text/Pandoc/Readers/MediaWiki.hs b/src/Text/Pandoc/Readers/MediaWiki.hs index 2b938cd82..0432915bc 100644 --- a/src/Text/Pandoc/Readers/MediaWiki.hs +++ b/src/Text/Pandoc/Readers/MediaWiki.hs @@ -91,7 +91,7 @@ nested p = do return res specialChars :: [Char] -specialChars = "'[]<=&*{}|\"" +specialChars = "'[]<=&*{}|\":\\" spaceChars :: [Char] spaceChars = " \n\t" @@ -380,8 +380,9 @@ defListItem = try $ do terms <- mconcat . intersperse B.linebreak <$> many defListTerm -- we allow dd with no dt, or dt with no dd defs <- if B.isNull terms - then many1 $ listItem ':' - else many $ listItem ':' + then notFollowedBy (try $ string ":<math>") *> + many1 (listItem ':') + else many (listItem ':') return (terms, defs) defListTerm :: MWParser Inlines @@ -462,6 +463,7 @@ inline = whitespace <|> image <|> internalLink <|> externalLink + <|> math <|> inlineTag <|> B.singleton <$> charRef <|> inlineHtml @@ -472,6 +474,16 @@ inline = whitespace str :: MWParser Inlines str = B.str <$> many1 (noneOf $ specialChars ++ spaceChars) +math :: MWParser Inlines +math = (B.displayMath <$> try (char ':' >> charsInTags "math")) + <|> (B.math <$> charsInTags "math") + <|> (B.displayMath <$> try (dmStart *> manyTill anyChar dmEnd)) + <|> (B.math <$> try (mStart *> manyTill (satisfy (/='\n')) mEnd)) + where dmStart = string "\\[" + dmEnd = try (string "\\]") + mStart = string "\\(" + mEnd = try (string "\\)") + variable :: MWParser String variable = try $ do string "{{{" @@ -495,7 +507,6 @@ inlineTag = do TagOpen "del" _ -> B.strikeout <$> inlinesInTags "del" TagOpen "sub" _ -> B.subscript <$> inlinesInTags "sub" TagOpen "sup" _ -> B.superscript <$> inlinesInTags "sup" - TagOpen "math" _ -> B.math <$> charsInTags "math" TagOpen "code" _ -> B.code <$> charsInTags "code" TagOpen "tt" _ -> B.code <$> charsInTags "tt" TagOpen "hask" _ -> B.codeWith ("",["haskell"],[]) <$> charsInTags "hask" |