mirror of
https://github.com/sdiehl/write-you-a-haskell.git
synced 2024-09-11 19:47:31 +03:00
Rewrite includes.hs
* It is now a pandoc filter * It also handles the injection of latex_macros
This commit is contained in:
parent
fe022ab012
commit
784150e7f1
29
includes.hs
29
includes.hs
@ -2,8 +2,13 @@
|
||||
|
||||
import Text.Read
|
||||
import Control.Monad.State
|
||||
|
||||
import Control.Monad
|
||||
import Text.Pandoc
|
||||
import Data.Monoid
|
||||
import Control.Applicative
|
||||
|
||||
import Text.Pandoc.JSON
|
||||
import Text.Pandoc.Walk
|
||||
|
||||
slice :: Int -> Int -> [a] -> [a]
|
||||
slice from to xs = take (to - from + 1) (drop from xs)
|
||||
@ -38,9 +43,21 @@ doHtml cb@(CodeBlock (id, classes, namevals) contents) =
|
||||
Nothing -> return cb
|
||||
doHtml x = return x
|
||||
|
||||
injectLatexMacros :: Maybe Format -> Pandoc -> IO Pandoc
|
||||
injectLatexMacros (Just fmt) p = do
|
||||
macros <- readFile "latex_macros"
|
||||
let block =
|
||||
case fmt of
|
||||
Format "html" ->
|
||||
Div ("",[],[("style","display:none")]) . (:[])
|
||||
. Para . (:[]) . Math DisplayMath $ macros
|
||||
Format "latex" -> RawBlock "latex" macros
|
||||
return (Pandoc nullMeta [block] <> p)
|
||||
injectLatexMacros _ _ = return mempty
|
||||
|
||||
main :: IO ()
|
||||
main = getContents >>= return . readMarkdown def
|
||||
>>= bottomUpM doInclude
|
||||
>>= bottomUpM doSlice
|
||||
>>= bottomUpM doHtml
|
||||
>>= putStrLn . writeMarkdown def
|
||||
main = toJSONFilter
|
||||
((\fmt -> injectLatexMacros fmt
|
||||
>=> walkM doInclude
|
||||
>=> walkM doSlice
|
||||
>=> walkM doHtml) :: Maybe Format -> Pandoc -> IO Pandoc)
|
||||
|
@ -1,5 +1,3 @@
|
||||
<div style="display:none">
|
||||
$$
|
||||
\newcommand{\andalso}{\quad\quad}
|
||||
\newcommand{\infabbrev}[2]{\infax{#1 \quad\eqdef\quad #2}}
|
||||
\newcommand{\infrule}[2]{\dfrac{#1}{#2}}
|
||||
@ -13,7 +11,5 @@ $$
|
||||
\newcommand{\BV}[1]{\mathtt{bv}(#1)}
|
||||
\newcommand{\compiles}[1]{\text{C}\llbracket{#1}\rrbracket}
|
||||
\newcommand{\exec}[1]{\text{E}\llbracket{#1}\rrbracket}
|
||||
\newcommand{\t}[1]{\mathtt{#1}}
|
||||
\renewcommand{\t}[1]{\mathtt{#1}}
|
||||
\newcommand{\ite}[3]{\text{if }#1\text{ then }#2\text{ else }#3}
|
||||
$$
|
||||
</div>
|
||||
|
Loading…
Reference in New Issue
Block a user