From e0624cebea1beeee66b18dfd9eb90882b02e6c33 Mon Sep 17 00:00:00 2001 From: Nikita Tchayka <nikitatchayka@gmail.com> Date: Thu, 24 Aug 2017 16:59:25 +0100 Subject: [PATCH] (25) Fixes #25 --- src/common/HaskellDo/State.hs | 2 ++ src/ghc-specific/Foreign/MathJax.hs | 5 +++++ src/ghcjs-specific/Foreign/MathJax.hs | 11 +++++++++++ static/out.jsexe/index.html | 8 ++++++++ 4 files changed, 26 insertions(+) create mode 100644 src/ghc-specific/Foreign/MathJax.hs create mode 100644 src/ghcjs-specific/Foreign/MathJax.hs diff --git a/src/common/HaskellDo/State.hs b/src/common/HaskellDo/State.hs index 0724af2..5374a49 100644 --- a/src/common/HaskellDo/State.hs +++ b/src/common/HaskellDo/State.hs @@ -33,6 +33,7 @@ import qualified HaskellDo.Compilation.Types as Compilation import qualified HaskellDo.Toolbar.State as Toolbar import qualified HaskellDo.Toolbar.Types as Toolbar import qualified Foreign.JQuery as JQuery +import qualified Foreign.MathJax as MathJax initialAppState :: AppState initialAppState = AppState @@ -98,6 +99,7 @@ _update (ToolbarAction Toolbar.Compile) appState = do Compilation.Compile (compilationState appState) localIO $ JQuery.hide ".dimmedBackground" + localIO $ MathJax.typeset "outputDisplay" return appState { compilationState = newCompilationState } diff --git a/src/ghc-specific/Foreign/MathJax.hs b/src/ghc-specific/Foreign/MathJax.hs new file mode 100644 index 0000000..303dd0c --- /dev/null +++ b/src/ghc-specific/Foreign/MathJax.hs @@ -0,0 +1,5 @@ +module Foreign.MathJax where + +typeset :: String -> IO () +typeset _ = return () + diff --git a/src/ghcjs-specific/Foreign/MathJax.hs b/src/ghcjs-specific/Foreign/MathJax.hs new file mode 100644 index 0000000..0938943 --- /dev/null +++ b/src/ghcjs-specific/Foreign/MathJax.hs @@ -0,0 +1,11 @@ +module Foreign.MathJax where + +import GHCJS.Types +import Data.JSString + +foreign import javascript unsafe "MathJax.Hub.Queue(['Typeset', MathJax.Hub, $1]);" + js_typeset :: JSString -> IO () + +typeset :: String -> IO () +typeset = js_typeset . pack + diff --git a/static/out.jsexe/index.html b/static/out.jsexe/index.html index 8cc92b5..75a75e8 100644 --- a/static/out.jsexe/index.html +++ b/static/out.jsexe/index.html @@ -40,7 +40,15 @@ <script src="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.25.2/mode/haskell/haskell.min.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.25.2/mode/htmlmixed/htmlmixed.min.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.25.2/mode/meta.min.js"></script> + <script src='https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.0/MathJax.js?config=TeX-MML-AM_CHTML'></script> <script> + MathJax.Hub.Config({ + tex2jax: { + inlineMath: [ ['$','$'], ["\\(","\\)"] ], + displayMath: [ ['$$','$$'], ["\\[","\\]"] ], + processEscapes: false, + } + }) let cmdOrCtrlReturnPressed = false; let alreadyHighlighted = false; </script>