blob: 40a8ce34d580c4e91769b36e22a8bcaba34af2fd (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
|
module IncludeFilePlugin (transform) where
import Text.Pandoc
import Text.Pandoc.Shared
import Control.Monad
-- This plugin allows you to include the contents of an
-- external file in a delimited code block like this:
--
-- ~~~ {include="filename"}
-- ~~~
--
-- Trailing newlines are trimmed.
transform :: Block -> IO Block
transform cb@(CodeBlock (id, classes, namevals) contents) =
case lookup "include" namevals of
Just f -> return . (CodeBlock (id, classes, namevals) . stripTrailingNewlines) =<< readFile f
Nothing -> return cb
transform x = return x
|