git.iko.soy/typeable/pandoc
on master help sign in
Implemented tex_math extensions in markdown writer.
5d83751John MacFarlane
src/Text/Pandoc/Writers/Markdown.hs+18−4
@@ -42,6 +42,7 @@ import Text.Pandoc.Pretty
42import Control.Monad.State
42import Control.Monad.State
43import qualified Data.Set as Set
43import qualified Data.Set as Set
44import Text.Pandoc.Writers.HTML (writeHtmlString)
44import Text.Pandoc.Writers.HTML (writeHtmlString)
45+import Text.Pandoc.Readers.TeXMath (readTeXMath)
45import Text.HTML.TagSoup (renderTags, parseTags, isTagText, Tag(..))
46import Text.HTML.TagSoup (renderTags, parseTags, isTagText, Tag(..))
46
47
47type Notes = [[Block]]
48type Notes = [[Block]]
@@ -531,10 +532,23 @@ inlineToMarkdown _ (Str str) = do
531 if stPlain st
532 if stPlain st
532 then return $ text str
533 then return $ text str
533 else return $ text $ escapeString str
534 else return $ text $ escapeString str
534−inlineToMarkdown _ (Math InlineMath str) =
535+inlineToMarkdown opts (Math InlineMath str)
536+ | isEnabled Ext_tex_math_dollars opts =
537+ return $ "$" <> text str <> "$"
538+ | isEnabled Ext_tex_math_single_backslash opts =
539+ return $ "\\(" <> text str <> "\\)"
540+ | isEnabled Ext_tex_math_double_backslash opts =
535− return $ "$" <> text str <> "$"
541+ return $ "\\\\(" <> text str <> "\\\\)"
542+ | otherwise = inlineListToMarkdown opts $ readTeXMath str
536−inlineToMarkdown _ (Math DisplayMath str) =
543+inlineToMarkdown opts (Math DisplayMath str)
544+ | isEnabled Ext_tex_math_dollars opts =
537− return $ "$$" <> text str <> "$$"
545+ return $ "$$" <> text str <> "$$"
546+ | isEnabled Ext_tex_math_single_backslash opts =
547+ return $ "\\[" <> text str <> "\\]"
548+ | isEnabled Ext_tex_math_double_backslash opts =
549+ return $ "\\\\[" <> text str <> "\\\\]"
550+ | otherwise = (\x -> cr <> x <> cr) `fmap`
551+ inlineListToMarkdown opts (readTeXMath str)
538inlineToMarkdown opts (RawInline f str)
552inlineToMarkdown opts (RawInline f str)
539 | f == "html" || f == "markdown" ||
553 | f == "html" || f == "markdown" ||
540 (isEnabled Ext_raw_tex opts && (f == "latex" || f == "tex")) =
554 (isEnabled Ext_raw_tex opts && (f == "latex" || f == "tex")) =