module Text.BlogLiterately.LaTeX
(
rawTeXify
, wpTeXify
) where
import Data.List (isPrefixOf)
import Text.Pandoc
rawTeXify :: Pandoc -> Pandoc
rawTeXify = bottomUp formatDisplayTex . bottomUp formatInlineTex
where formatInlineTex :: [Inline] -> [Inline]
formatInlineTex (Math InlineMath tex : is)
= (RawInline (Format "html") ("$" ++ tex ++ "$")) : is
formatInlineTex is = is
formatDisplayTex :: [Block] -> [Block]
formatDisplayTex (Para [Math DisplayMath tex] : bs)
= RawBlock (Format "html") ("\n\\[" ++ tex ++ "\\]\n")
: bs
formatDisplayTex bs = bs
wpTeXify :: Pandoc -> Pandoc
wpTeXify = bottomUp formatDisplayTex . bottomUp formatInlineTex
where formatInlineTex :: [Inline] -> [Inline]
formatInlineTex (Math InlineMath tex : is)
= (Str $ "$latex " ++ unPrefix "latex" tex ++ "$") : is
formatInlineTex is = is
formatDisplayTex :: [Block] -> [Block]
formatDisplayTex (Para [Math DisplayMath tex] : bs)
= RawBlock (Format "html") "<p><div style=\"text-align: center\">"
: Plain [Str $ "$latex " ++ "\\displaystyle " ++ unPrefix "latex" tex ++ "$"]
: RawBlock (Format "html") "</div></p>"
: bs
formatDisplayTex bs = bs
unPrefix pre s
| pre `isPrefixOf` s = drop (length pre) s
| otherwise = s