Skip to content

Commit

Permalink
Support mathjax as a math option.
Browse files Browse the repository at this point in the history
Added MathJax as MathMethod, and mathjax as an option in
the 'math' config field.

Resolves GoogleCode 122.
  • Loading branch information
John MacFarlane committed Sep 3, 2011
1 parent b823b89 commit 1892d65
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 14 deletions.
3 changes: 2 additions & 1 deletion Network/Gitit/Config.hs
Expand Up @@ -38,7 +38,7 @@ import Data.List (intercalate)
import Data.Char (toLower, toUpper, isDigit) import Data.Char (toLower, toUpper, isDigit)
import Paths_gitit (getDataFileName) import Paths_gitit (getDataFileName)
import System.FilePath ((</>)) import System.FilePath ((</>))
import Text.Pandoc hiding (MathML, WebTeX) import Text.Pandoc hiding (MathML, WebTeX, MathJax)


forceEither :: Show e => Either e a -> a forceEither :: Show e => Either e a -> a
forceEither = either (error . show) id forceEither = either (error . show) id
Expand Down Expand Up @@ -130,6 +130,7 @@ extractConfig cp = do
, mathMethod = case map toLower cfMathMethod of , mathMethod = case map toLower cfMathMethod of
"jsmath" -> JsMathScript "jsmath" -> JsMathScript
"mathml" -> MathML "mathml" -> MathML
"mathjax" -> MathJax "https://d3eoax9i5htok0.cloudfront.net/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML"
"google" -> WebTeX "http://chart.apis.google.com/chart?cht=tx&chl=" "google" -> WebTeX "http://chart.apis.google.com/chart?cht=tx&chl="
_ -> RawTeX _ -> RawTeX
, defaultLHS = lhs , defaultLHS = lhs
Expand Down
4 changes: 3 additions & 1 deletion Network/Gitit/ContentTransformer.hs
Expand Up @@ -86,7 +86,7 @@ import Prelude hiding (catch)
import System.FilePath import System.FilePath
import Text.HTML.SanitizeXSS (sanitizeBalance) import Text.HTML.SanitizeXSS (sanitizeBalance)
import Text.Highlighting.Kate import Text.Highlighting.Kate
import Text.Pandoc hiding (MathML, WebTeX) import Text.Pandoc hiding (MathML, WebTeX, MathJax)
import Text.Pandoc.Shared (ObfuscationMethod(..)) import Text.Pandoc.Shared (ObfuscationMethod(..))
import Text.XHtml hiding ( (</>), dir, method, password, rev ) import Text.XHtml hiding ( (</>), dir, method, password, rev )
import qualified Data.Text as T import qualified Data.Text as T
Expand Down Expand Up @@ -347,6 +347,7 @@ pandocToHtml pandocContents = do
case mathMethod cfg of case mathMethod cfg of
MathML -> Pandoc.MathML Nothing MathML -> Pandoc.MathML Nothing
WebTeX u -> Pandoc.WebTeX u WebTeX u -> Pandoc.WebTeX u
MathJax u -> Pandoc.MathJax u
_ -> JsMath (Just $ base' ++ _ -> JsMath (Just $ base' ++
"/js/jsMath/easy/load.js") "/js/jsMath/easy/load.js")
, writerTableOfContents = toc , writerTableOfContents = toc
Expand Down Expand Up @@ -452,6 +453,7 @@ addMathSupport c = do
JsMathScript -> addScripts l ["jsMath/easy/load.js"] JsMathScript -> addScripts l ["jsMath/easy/load.js"]
MathML -> addScripts l ["MathMLinHTML.js"] MathML -> addScripts l ["MathMLinHTML.js"]
WebTeX _ -> l WebTeX _ -> l
MathJax u -> addScripts l [u]
RawTeX -> l RawTeX -> l
return c return c


Expand Down
6 changes: 5 additions & 1 deletion Network/Gitit/Layout.hs
Expand Up @@ -75,8 +75,12 @@ filledPageTemplate :: String -> Config -> PageLayout -> Html ->
filledPageTemplate base' cfg layout htmlContents templ = filledPageTemplate base' cfg layout htmlContents templ =
let rev = pgRevision layout let rev = pgRevision layout
page = pgPageName layout page = pgPageName layout
prefixedScript x = case x of
'h':'t':'t':'p':_ -> x
_ -> base' ++ "/js/" ++ x

scripts = ["jquery.min.js", "jquery-ui.packed.js", "footnotes.js"] ++ pgScripts layout scripts = ["jquery.min.js", "jquery-ui.packed.js", "footnotes.js"] ++ pgScripts layout
scriptLink x = script ! [src (base' ++ "/js/" ++ x), scriptLink x = script ! [src (prefixedScript x),
thetype "text/javascript"] << noHtml thetype "text/javascript"] << noHtml
javascriptlinks = renderHtmlFragment $ concatHtml $ map scriptLink scripts javascriptlinks = renderHtmlFragment $ concatHtml $ map scriptLink scripts
tabli tab = if tab == pgSelectedTab layout tabli tab = if tab == pgSelectedTab layout
Expand Down
2 changes: 1 addition & 1 deletion Network/Gitit/Types.hs
Expand Up @@ -42,7 +42,7 @@ data PageType = Markdown | RST | LaTeX | HTML | Textile


data FileStoreType = Git | Darcs | Mercurial deriving Show data FileStoreType = Git | Darcs | Mercurial deriving Show


data MathMethod = MathML | JsMathScript | WebTeX String | RawTeX data MathMethod = MathML | JsMathScript | WebTeX String | RawTeX | MathJax String
deriving (Read, Show, Eq) deriving (Read, Show, Eq)


data AuthenticationLevel = Never | ForModify | ForRead data AuthenticationLevel = Never | ForModify | ForRead
Expand Down
20 changes: 10 additions & 10 deletions data/default.conf
Expand Up @@ -61,16 +61,16 @@ default-page-type: Markdown


math: MathML math: MathML
# specifies how LaTeX math is to be displayed. Possible values # specifies how LaTeX math is to be displayed. Possible values
# are MathML, raw, jsMath, and google. If mathml is selected, gitit will # are MathML, raw, mathjax, jsMath, and google. If mathml is selected,
# convert LaTeX math to MathML and link in a script, MathMLinHTML.js, # gitit will convert LaTeX math to MathML and link in a script,
# that allows the MathML to be seen in Gecko browsers, IE + # MathMLinHTML.js, that allows the MathML to be seen in Gecko browsers, IE +
# mathplayer, and Opera. In other browsers you may get a jumble # mathplayer, and Opera. In other browsers you may get a jumble of characters.
# of characters. If raw is selected, the LaTeX math will be displayed # If raw is selected, the LaTeX math will be displayed as raw LaTeX math.
# as raw LaTeX math. If jsMath is selected, gitit will link to # If mathjax is selected, gitit will link to the remote mathjax script.
# the script /js/jsMath/easy/load.js, and will assume that jsMath # If jsMath is selected, gitit will link to the script /js/jsMath/easy/load.js,
# has been installed into the js/jsMath directory. This is the most # and will assume that jsMath has been installed into the js/jsMath directory.
# portable solution. If google is selected, the google chart API is # This is the most portable solution. If google is selected, the google chart
# called to render the formula as an image. This requires a connection # API is called to render the formula as an image. This requires a connection
# to google, and might raise a technical or a privacy problem. # to google, and might raise a technical or a privacy problem.


show-lhs-bird-tracks: no show-lhs-bird-tracks: no
Expand Down

0 comments on commit 1892d65

Please sign in to comment.