file2Block
This commit is contained in:
parent
166429a005
commit
844b454e9f
@ -5,7 +5,9 @@ import qualified Data.Text.IO as TIO
|
||||
import qualified Data.Text as T
|
||||
|
||||
file2Block :: FilePath -> IO [Block]
|
||||
|
||||
file2Block f = do
|
||||
contents <- TIO.readFile f
|
||||
return [Plain [Str contents]]
|
||||
|
||||
doInclude :: Block -> IO Block
|
||||
doInclude cb@(Div (id, classes, namevals) contents) =
|
||||
|
22
output.html
22
output.html
@ -1,6 +1,28 @@
|
||||
<p>Here’s the pandoc README:</p>
|
||||
<div class="sourceCode" id="cb1" data-include="filter.hs"><pre
|
||||
class="sourceCode haskell"><code class="sourceCode haskell"><span id="cb1-1"><a href="#cb1-1" aria-hidden="true" tabindex="-1"></a><span class="dt">Foo</span><span class="ot">::</span> <span class="dt">Div</span> <span class="ot">-></span> <span class="dt">Div</span></span></code></pre></div>
|
||||
<div data-include="filter.hs">
|
||||
#!/usr/bin/env runhaskell
|
||||
-- filter.hs
|
||||
import Text.Pandoc.JSON
|
||||
import qualified Data.Text.IO as TIO
|
||||
import qualified Data.Text as T
|
||||
|
||||
file2Block :: FilePath -> IO [Block]
|
||||
file2Block f = do
|
||||
contents <- TIO.readFile f
|
||||
return [Plain [Str contents]]
|
||||
|
||||
doInclude :: Block -> IO Block
|
||||
doInclude cb@(Div (id, classes, namevals) contents) =
|
||||
case lookup (T.pack "include") namevals of
|
||||
Just f -> Div (id, classes, namevals) <$>
|
||||
file2Block (T.unpack f)
|
||||
Nothing -> return cb
|
||||
doInclude x = return x
|
||||
|
||||
main :: IO ()
|
||||
main = toJSONFilter doInclude
|
||||
</div>
|
||||
<div class="Theorem">
|
||||
<p>test thm1</p>
|
||||
|
Loading…
x
Reference in New Issue
Block a user