diff options
author | John MacFarlane <jgm@berkeley.edu> | 2017-11-28 10:56:32 -0800 |
---|---|---|
committer | John MacFarlane <jgm@berkeley.edu> | 2017-11-28 10:56:32 -0800 |
commit | 00561b1bb956a5b4de291e80001cf752c38c4549 (patch) | |
tree | cd934ce66132923dd14f4bcc43cc6b454ba5a8bc /src/Text | |
parent | 8b0b4cd84860b08e6fefe59fde32c5677d7c65c8 (diff) | |
download | pandoc-00561b1bb956a5b4de291e80001cf752c38c4549.tar.gz |
Support `--webtex` for `gfm` output.
Diffstat (limited to 'src/Text')
-rw-r--r-- | src/Text/Pandoc/Writers/CommonMark.hs | 22 | ||||
-rw-r--r-- | src/Text/Pandoc/Writers/Markdown.hs | 5 |
2 files changed, 18 insertions, 9 deletions
diff --git a/src/Text/Pandoc/Writers/CommonMark.hs b/src/Text/Pandoc/Writers/CommonMark.hs index 8677dd840..f4d376458 100644 --- a/src/Text/Pandoc/Writers/CommonMark.hs +++ b/src/Text/Pandoc/Writers/CommonMark.hs @@ -39,6 +39,7 @@ import Data.List (transpose) import Data.Monoid (Any (..), (<>)) import Data.Text (Text) import qualified Data.Text as T +import Network.HTTP (urlEncode) import Text.Pandoc.Class (PandocMonad) import Text.Pandoc.Definition import Text.Pandoc.Options @@ -276,12 +277,21 @@ inlineToNodes opts (Quoted qt ils) = | isEnabled Ext_smart opts -> ("\"", "\"") | otherwise -> ("“", "”") inlineToNodes _ (Code _ str) = (node (CODE (T.pack str)) [] :) -inlineToNodes _ (Math mt str) = - case mt of - InlineMath -> - (node (HTML_INLINE (T.pack ("\\(" ++ str ++ "\\)"))) [] :) - DisplayMath -> - (node (HTML_INLINE (T.pack ("\\[" ++ str ++ "\\]"))) [] :) +inlineToNodes opts (Math mt str) = + case writerHTMLMathMethod opts of + WebTeX url -> + let core = inlineToNodes opts + (Image nullAttr [Str str] (url ++ urlEncode str, str)) + sep = if mt == DisplayMath + then (node LINEBREAK [] :) + else id + in (sep . core . sep) + _ -> + case mt of + InlineMath -> + (node (HTML_INLINE (T.pack ("\\(" ++ str ++ "\\)"))) [] :) + DisplayMath -> + (node (HTML_INLINE (T.pack ("\\[" ++ str ++ "\\]"))) [] :) inlineToNodes opts (Span _ ils) = (inlinesToNodes opts ils ++) inlineToNodes opts (Cite _ ils) = (inlinesToNodes opts ils ++) inlineToNodes _ (Note _) = id -- should not occur diff --git a/src/Text/Pandoc/Writers/Markdown.hs b/src/Text/Pandoc/Writers/Markdown.hs index a8452f468..7a3d204f2 100644 --- a/src/Text/Pandoc/Writers/Markdown.hs +++ b/src/Text/Pandoc/Writers/Markdown.hs @@ -1068,9 +1068,8 @@ inlineToMarkdown opts (Str str) = do return $ text str' inlineToMarkdown opts (Math InlineMath str) = case writerHTMLMathMethod opts of - WebTeX url -> - inlineToMarkdown opts (Image nullAttr [Str str] - (url ++ urlEncode str, str)) + WebTeX url -> inlineToMarkdown opts + (Image nullAttr [Str str] (url ++ urlEncode str, str)) _ | isEnabled Ext_tex_math_dollars opts -> return $ "$" <> text str <> "$" | isEnabled Ext_tex_math_single_backslash opts -> |