File tree Expand file tree Collapse file tree 4 files changed +77
-0
lines changed Expand file tree Collapse file tree 4 files changed +77
-0
lines changed Original file line number Diff line number Diff line change 1+ #!/usr/bin/env runhaskell
2+ -- includes.hs
3+
4+ module Text.Pandoc.Include where
5+
6+ import Control.Monad
7+ import Data.List.Split
8+
9+ import Text.Pandoc.JSON
10+ import Text.Pandoc
11+ import Text.Pandoc.Error
12+
13+
14+ stripPandoc :: Either PandocError Pandoc -> [Block ]
15+ stripPandoc p =
16+ case p of
17+ Left _ -> [Null ]
18+ Right (Pandoc _ blocks) -> blocks
19+
20+
21+ ioReadMarkdown :: String -> IO (Either PandocError Pandoc )
22+ ioReadMarkdown content = return (readMarkdown def content)
23+
24+
25+ getContent :: String -> IO [Block ]
26+ getContent file = do
27+ c <- readFile file
28+ p <- ioReadMarkdown c
29+ return (stripPandoc p)
30+
31+
32+ doInclude :: Block -> IO [Block ]
33+ doInclude cb@ (CodeBlock (_, classes, _) list) =
34+ if " include" `elem` classes
35+ then do
36+ -- msum $ map getContent (splitOn "\n" list)
37+ files <- return $ wordsBy (== ' \n ' ) list
38+ contents <- return $ map getContent files
39+ result <- return $ msum contents
40+ result
41+ -- msum $ map (\file ->
42+ -- do
43+ -- c <- readFile file
44+ -- p <- ioReadMarkdown c
45+ -- return (stripPandoc p)
46+ -- ) (wordsBy (=='\n') list)
47+ else
48+ return [cb]
49+ doInclude x = return [x]
50+
51+
52+ main :: IO ()
53+ main = toJSONFilter doInclude
Original file line number Diff line number Diff line change 1+ # Alpha!
2+
3+ Text from alpha.
4+
5+ ``` include
6+ beta.md
7+ ```
8+
9+ Text after beta include.
Original file line number Diff line number Diff line change 1+ BETA!!!
Original file line number Diff line number Diff line change 1+ text
2+
3+ ``` include
4+ alpha.md
5+ alpha.md
6+ beta.md
7+ gamma.md
8+ #alpha.md
9+ ```
10+ ``` include
11+ beta.md
12+ ```
13+
14+ text
You can’t perform that action at this time.
0 commit comments