-
Notifications
You must be signed in to change notification settings - Fork 0
/
tex_filter.hs
executable file
·39 lines (32 loc) · 1.23 KB
/
tex_filter.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#!/usr/bin/env runghc
import Data.Generics
import Text.Pandoc
import Text.JSON.Generic
apply :: Data a => (a -> a) -> Pandoc -> Pandoc
apply f = everywhere (mkT f) -- see 'Scrap Your Boilerplate' reference.
convert_raw_block :: Block -> Block
convert_raw_block (RawBlock "latex" content) = RawBlock "html" content
convert_raw_block other = other
convert_raw_inline :: Inline -> Inline
convert_raw_inline (RawInline "tex" content) = RawInline "html" content
convert_raw_inline other = other
-- need to patch the output to support those references on the mathjax side
-- see: https://github.com/mathjax/MathJax/issues/71
-- basically, need in the preamble:
--
-- <script type="text/x-mathjax-config">
-- MathJax.Hub.Config({
-- TeX: { equationNumbers: { autoNumber: "AMS" } }
-- });
-- </script>
-- <script
-- type="text/javascript"
-- src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML">
-- </script>
--
-- try with tagsoup ? http://hackage.haskell.org/packages/archive/tagsoup/latest/doc/html/Text-HTML-TagSoup.html
--
main = do
input <- getContents
let output = (encodeJSON . (apply convert_raw_block) . (apply convert_raw_inline) . decodeJSON) input
putStr output