aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn MacFarlane <jgm@berkeley.edu>2012-08-11 22:24:06 -0700
committerJohn MacFarlane <jgm@berkeley.edu>2012-08-11 22:24:06 -0700
commit5d83751af4e5df61bf41c3fc9eb79031d772f2bb (patch)
tree7a7f389859bf2bbe6b5a6f85f97f89c61ab65faa
parente520762543f85e7457c2cd1b784355dae616bdc3 (diff)
downloadpandoc-5d83751af4e5df61bf41c3fc9eb79031d772f2bb.tar.gz
Implemented tex_math extensions in markdown writer.
-rw-r--r--src/Text/Pandoc/Writers/Markdown.hs22
1 files changed, 18 insertions, 4 deletions
diff --git a/src/Text/Pandoc/Writers/Markdown.hs b/src/Text/Pandoc/Writers/Markdown.hs
index be7af9b6c..c21c735c3 100644
--- a/src/Text/Pandoc/Writers/Markdown.hs
+++ b/src/Text/Pandoc/Writers/Markdown.hs
@@ -42,6 +42,7 @@ import Text.Pandoc.Pretty
import Control.Monad.State
import qualified Data.Set as Set
import Text.Pandoc.Writers.HTML (writeHtmlString)
+import Text.Pandoc.Readers.TeXMath (readTeXMath)
import Text.HTML.TagSoup (renderTags, parseTags, isTagText, Tag(..))
type Notes = [[Block]]
@@ -531,10 +532,23 @@ inlineToMarkdown _ (Str str) = do
if stPlain st
then return $ text str
else return $ text $ escapeString str
-inlineToMarkdown _ (Math InlineMath str) =
- return $ "$" <> text str <> "$"
-inlineToMarkdown _ (Math DisplayMath str) =
- return $ "$$" <> text str <> "$$"
+inlineToMarkdown opts (Math InlineMath str)
+ | isEnabled Ext_tex_math_dollars opts =
+ return $ "$" <> text str <> "$"
+ | isEnabled Ext_tex_math_single_backslash opts =
+ return $ "\\(" <> text str <> "\\)"
+ | isEnabled Ext_tex_math_double_backslash opts =
+ return $ "\\\\(" <> text str <> "\\\\)"
+ | otherwise = inlineListToMarkdown opts $ readTeXMath str
+inlineToMarkdown opts (Math DisplayMath str)
+ | isEnabled Ext_tex_math_dollars opts =
+ return $ "$$" <> text str <> "$$"
+ | isEnabled Ext_tex_math_single_backslash opts =
+ return $ "\\[" <> text str <> "\\]"
+ | isEnabled Ext_tex_math_double_backslash opts =
+ return $ "\\\\[" <> text str <> "\\\\]"
+ | otherwise = (\x -> cr <> x <> cr) `fmap`
+ inlineListToMarkdown opts (readTeXMath str)
inlineToMarkdown opts (RawInline f str)
| f == "html" || f == "markdown" ||
(isEnabled Ext_raw_tex opts && (f == "latex" || f == "tex")) =