Permalink
Browse files

Use pandoc's new mathml capabilities for MathML math method.

  • Loading branch information...
1 parent b6a03a1 commit c63fec048827423d26fb86dc9a5012675013c931 @jgm committed Mar 20, 2010
Showing with 18 additions and 41 deletions.
  1. +5 −2 CHANGES
  2. +1 −1 Network/Gitit/Config.hs
  3. +10 −36 Network/Gitit/ContentTransformer.hs
  4. +1 −1 data/default.conf
  5. +1 −1 gitit.cabal
View
@@ -4,7 +4,10 @@ Version 0.7.3 released 20 Mar 2010
(Based on a patch by gwern.)
* Added markdown export.
-
+
+* Use pandoc's new MathML math mode for more efficient
+ MathML.
+
* Improved multi-wiki example code in haddocks.
* Added session-timeout config setting.
@@ -23,7 +26,7 @@ Version 0.7.3 released 20 Mar 2010
* Added pandoc-user-data config option, allowing the user
to specify a directory with e.g. templates that override
the defaults used for exported pages.
-
+
* Fix filesToClean GHC panic when loading plugins on GHC HEAD
* Fixed problem with doubled // in updir links.
View
@@ -45,7 +45,7 @@ import Prelude hiding (readFile)
import System.IO.UTF8
#endif
import System.FilePath ((</>))
-import Text.Pandoc
+import Text.Pandoc hiding (MathML)
forceEither :: Show e => Either e a -> a
forceEither = either (error . show) id
@@ -79,7 +79,8 @@ import Network.Gitit.Page (stringToPage)
import Network.Gitit.Cache (lookupCache, cacheContents)
import qualified Data.FileStore as FS
import Data.Maybe (mapMaybe)
-import Text.Pandoc
+import Text.Pandoc hiding (MathML)
+import qualified Text.Pandoc as Pandoc
import Text.Pandoc.Shared (ObfuscationMethod(..))
import Text.XHtml hiding ( (</>), dir, method, password, rev )
import Text.Highlighting.Kate
@@ -91,8 +92,6 @@ import Control.Exception (throwIO, catch)
import Network.URI (isUnescapedInURI, escapeURIString)
import qualified Data.ByteString as S (concat)
import qualified Data.ByteString.Lazy as L (toChunks, fromChunks)
-import Text.XML.Light
-import Text.TeXMath
--
-- ContentTransformer runners
@@ -337,11 +336,15 @@ pandocToHtml pandocContents = do
base' <- lift getWikiBase
toc <- liftM ctxTOC get
bird <- liftM ctxBirdTracks get
+ cfg <- lift getConfig
return $ writeHtml defaultWriterOptions{
writerStandalone = True
, writerTemplate = "$if(toc)$\n$toc$\n$endif$\n$body$"
- , writerHTMLMathMethod = JsMath
- (Just $ base' ++ "/js/jsMath/easy/load.js")
+ , writerHTMLMathMethod =
+ case mathMethod cfg of
+ MathML -> Pandoc.MathML Nothing
+ _ -> JsMath (Just $ base' ++
+ "/js/jsMath/easy/load.js")
, writerTableOfContents = toc
, writerLiterateHaskell = bird
-- note: javascript obfuscation gives problems on preview
@@ -401,12 +404,7 @@ applyTransform inp transform = do
applyPageTransforms :: Pandoc -> ContentTransformer Pandoc
applyPageTransforms c = do
xforms <- getPageTransforms
- cfg <- lift getConfig
- params <- getParams
- let xforms' = case mathMethod cfg of
- MathML -> mathMLTransform (pFormat params) : xforms
- _ -> xforms
- foldM applyTransform c (wikiLinksTransform : xforms')
+ foldM applyTransform c (wikiLinksTransform : xforms)
-- | Applies all the pre-parse transform plugins to a Page object.
applyPreParseTransforms :: Page -> ContentTransformer Page
@@ -448,9 +446,7 @@ addMathSupport c = do
updateLayout $ \l ->
case mathMethod conf of
JsMathScript -> addScripts l ["jsMath/easy/load.js"]
- -- for MathML, the script is added by mathMLTransform, only
- -- if the page contains math:
- MathML -> l
+ MathML -> addScripts l ["MathMLInHTML.js"]
RawTeX -> l
return c
@@ -509,28 +505,6 @@ convertWikiLinks (Link ref ("", "")) =
Link ref (inlinesToURL ref, "Go to wiki page")
convertWikiLinks x = x
-mathMLTransform :: String -> Pandoc -> PluginM Pandoc
-mathMLTransform format inp | format `elem` ["","S5"] = do
- let (Pandoc m blks, mathUsed) = runState (processWithM convertTeXMathToMathML inp) False
- let scriptLink = RawHtml "<script type=\"text/javascript\" src=\"/js/MathMLinHTML.js\"></script>"
- let blks' = if mathUsed
- then blks ++ [scriptLink]
- else blks
- return $ Pandoc m blks'
-mathMLTransform _ inp = return inp
-
--- | Convert math to MathML. We put this in a Writer monad
--- to keep track of whether we've actually got any MathML; if not,
--- we can avoid linking a script.
-convertTeXMathToMathML :: Inline -> State Bool Inline
-convertTeXMathToMathML (Math t x) = do
- case texMathToMathML t' x of
- Left _ -> return $ Math t x
- Right v -> put True >> return (HtmlInline $ showXml v)
- where t' = if t == DisplayMath then DisplayBlock else DisplayInline
- showXml = ppcElement (useShortEmptyTags (const False) defaultConfigPP)
-convertTeXMathToMathML x = return x
-
-- | Derives a URL from a list of Pandoc Inline elements.
inlinesToURL :: [Inline] -> String
inlinesToURL = escapeURIString isUnescapedInURI  . encodeString . inlinesToString
View
@@ -50,7 +50,7 @@ default-page-type: Markdown
# rendered correctly if RST is selected. The same goes for LaTeX and
# HTML.
-math: MathML
+math: RawTeX
# specifies how LaTeX math is to be displayed. Possible values
# are MathML, raw, and jsMath. If mathml is selected, gitit will
# convert LaTeX math to MathML and link in a script, MathMLinHTML.js,
View
@@ -125,7 +125,7 @@ Executable gitit
happstack-util >= 0.3.2 && < 0.5, xml >= 1.3.5,
hslogger >= 1 && < 1.1, ConfigFile >= 1 && < 1.1,
feed >= 0.3.6 && < 0.4,
- cautious-file >= 0.1.5 && < 0.2, texmath
+ cautious-file >= 0.1.5 && < 0.2
if impl(ghc >= 6.10)
build-depends: base >= 4, syb
if flag(plugins)

0 comments on commit c63fec0

Please sign in to comment.