Skip to content

Commit

Permalink
Merge pull request #120 from theam/mathjax-support
Browse files Browse the repository at this point in the history
(25) Fixes #25
  • Loading branch information
Nikita Tchayka authored Aug 24, 2017
2 parents 7a31007 + e0624ce commit a8e807f
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/common/HaskellDo/State.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
}
Expand Down
5 changes: 5 additions & 0 deletions src/ghc-specific/Foreign/MathJax.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module Foreign.MathJax where

typeset :: String -> IO ()
typeset _ = return ()

11 changes: 11 additions & 0 deletions src/ghcjs-specific/Foreign/MathJax.hs
Original file line number Diff line number Diff line change
@@ -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

8 changes: 8 additions & 0 deletions static/out.jsexe/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down

1 comment on commit a8e807f

@ocramz
Copy link
Contributor

@ocramz ocramz commented on a8e807f Dec 25, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just noticed that this functionality could have been added via inliterate, following this example:

https://github.com/diffusionkinetics/open/blob/4838f1327678434e2e6c8732764b85bc17984251/plotlyhs/src/Graphics/Plotly/Blaze.hs

Please sign in to comment.