Permalink
Browse files

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

This reverts commit c63fec0.

Conflicts:

	Network/Gitit/ContentTransformer.hs
  • Loading branch information...
1 parent 798dfc0 commit cf93c6e944de7927cdcab3a104c0a58c829f5718 John MacFarlane committed Mar 22, 2010
Showing with 39 additions and 16 deletions.
  1. +2 −5 CHANGES
  2. +35 −9 Network/Gitit/ContentTransformer.hs
  3. +1 −1 data/default.conf
  4. +1 −1 gitit.cabal
View
@@ -14,10 +14,7 @@ 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.
@@ -36,7 +33,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.
@@ -80,7 +80,6 @@ import Network.Gitit.Cache (lookupCache, cacheContents)
import qualified Data.FileStore as FS
import Data.Maybe (mapMaybe)
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
@@ -90,6 +89,8 @@ import Control.Monad.State
import Control.Exception (throwIO, catch)
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
@@ -334,15 +335,11 @@ 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 =
- case mathMethod cfg of
- MathML -> Pandoc.MathML Nothing
- _ -> JsMath (Just $ base' ++
- "/js/jsMath/easy/load.js")
+ , writerHTMLMathMethod = JsMath
+ (Just $ base' ++ "/js/jsMath/easy/load.js")
, writerTableOfContents = toc
, writerLiterateHaskell = bird
-- note: javascript obfuscation gives problems on preview
@@ -402,7 +399,12 @@ applyTransform inp transform = do
applyPageTransforms :: Pandoc -> ContentTransformer Pandoc
applyPageTransforms c = do
xforms <- getPageTransforms
- foldM applyTransform c (wikiLinksTransform : xforms)
+ cfg <- lift getConfig
+ params <- getParams
+ let xforms' = case mathMethod cfg of
+ MathML -> mathMLTransform (pFormat params) : xforms
+ _ -> xforms
+ foldM applyTransform c (wikiLinksTransform : xforms')
-- | Applies all the pre-parse transform plugins to a Page object.
applyPreParseTransforms :: Page -> ContentTransformer Page
@@ -444,7 +446,9 @@ addMathSupport c = do
updateLayout $ \l ->
case mathMethod conf of
JsMathScript -> addScripts l ["jsMath/easy/load.js"]
- MathML -> addScripts l ["MathMLinHTML.js"]
+ -- for MathML, the script is added by mathMLTransform, only
+ -- if the page contains math:
+ MathML -> l
RawTeX -> l
return c
@@ -503,6 +507,28 @@ 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 = urlForPage . inlinesToString
View
@@ -50,7 +50,7 @@ default-page-type: Markdown
# rendered correctly if RST is selected. The same goes for LaTeX and
# HTML.
-math: RawTeX
+math: MathML
# 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
+ cautious-file >= 0.1.5 && < 0.2, texmath
if impl(ghc >= 6.10)
build-depends: base >= 4, syb
if flag(plugins)

0 comments on commit cf93c6e

Please sign in to comment.