aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn MacFarlane <jgm@berkeley.edu>2016-06-24 14:46:47 -0700
committerJohn MacFarlane <jgm@berkeley.edu>2016-06-24 14:57:21 -0700
commita4294800bfe91976697239ff15c1f87f518df6e8 (patch)
treef3ca7ecb34cfe2841ca96b6977a5f295af9cccfc
parent5bdf2171351472a4e5804607ee86c1c28268b148 (diff)
downloadpandoc-a4294800bfe91976697239ff15c1f87f518df6e8.tar.gz
Make --webtex work with the Markdown writer.
Closes #1177. This is a convenient option for people using websites whose Markdown flavors don't provide for math.
-rw-r--r--README2
-rw-r--r--src/Text/Pandoc/Writers/Markdown.hs29
2 files changed, 19 insertions, 12 deletions
diff --git a/README b/README
index ecbc248e0..e3904b74e 100644
--- a/README
+++ b/README
@@ -949,6 +949,8 @@ Math rendering in HTML
: Render TeX formulas using an external script that converts TeX
formulas to images. The formula will be concatenated with the URL
provided. If *URL* is not specified, the Google Chart API will be used.
+ Note: the `--webtex` option will affect Markdown output
+ as well as HTML.
`--katex`[`=`*URL*]
diff --git a/src/Text/Pandoc/Writers/Markdown.hs b/src/Text/Pandoc/Writers/Markdown.hs
index 1ff8d2ab9..b04e33085 100644
--- a/src/Text/Pandoc/Writers/Markdown.hs
+++ b/src/Text/Pandoc/Writers/Markdown.hs
@@ -55,6 +55,7 @@ import qualified Data.HashMap.Strict as H
import qualified Data.Vector as V
import qualified Data.Text as T
import qualified Data.Set as Set
+import Network.HTTP ( urlEncode )
type Notes = [[Block]]
type Ref = ([Inline], Target, Attr)
@@ -856,18 +857,22 @@ inlineToMarkdown opts (Str str) = do
if stPlain st
then return $ text str
else return $ text $ escapeString opts 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 = do
- plain <- gets stPlain
- inlineListToMarkdown opts $
- (if plain then makeMathPlainer else id) $
- texMathToInlines InlineMath str
+inlineToMarkdown opts (Math InlineMath str) =
+ case writerHTMLMathMethod opts of
+ 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 ->
+ return $ "\\(" <> text str <> "\\)"
+ | isEnabled Ext_tex_math_double_backslash opts ->
+ return $ "\\\\(" <> text str <> "\\\\)"
+ | otherwise -> do
+ plain <- gets stPlain
+ inlineListToMarkdown opts $
+ (if plain then makeMathPlainer else id) $
+ texMathToInlines InlineMath str
inlineToMarkdown opts (Math DisplayMath str)
| isEnabled Ext_tex_math_dollars opts =
return $ "$$" <> text str <> "$$"