git.iko.soy/typeable/pandoc
on ecbf338 help sign in
typeable/pandoc/plugins/IncludeFilePlugin.hs
19 lines 582 B history raw
1module IncludeFilePlugin (transform) where
2import Text.Pandoc
3import Text.Pandoc.Shared
4import Control.Monad
6-- This plugin allows you to include the contents of an
7-- external file in a delimited code block like this:
8--
9-- ~~~ {include="filename"}
10-- ~~~
11--
12-- Trailing newlines are trimmed.
14transform :: Block -> IO Block
15transform cb@(CodeBlock (id, classes, namevals) contents) =
16 case lookup "include" namevals of
17 Just f -> return . (CodeBlock (id, classes, namevals) . stripTrailingNewlines) =<< readFile f
18 Nothing -> return cb
19transform x = return x