Skip to content

Commit bb4ca08

Browse files
committed
Working on list of files, still only for 2-levels-deep
For the fix see: http://stackoverflow.com/questions/34031192/haskell-map-does-not-iterate-over-the-whole-list
1 parent 8329e6e commit bb4ca08

File tree

1 file changed

+17
-22
lines changed

1 file changed

+17
-22
lines changed

IncludeFilter.hs

Lines changed: 17 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
module Text.Pandoc.Include where
55

66
import Control.Monad
7-
import Data.List.Split
7+
import Data.List
8+
import System.Directory
89

910
import Text.Pandoc.JSON
1011
import Text.Pandoc
@@ -17,37 +18,31 @@ stripPandoc p =
1718
Left _ -> [Null]
1819
Right (Pandoc _ blocks) -> blocks
1920

20-
2121
ioReadMarkdown :: String -> IO(Either PandocError Pandoc)
22-
ioReadMarkdown content = return (readMarkdown def content)
23-
22+
ioReadMarkdown content = return $! readMarkdown def content
2423

2524
getContent :: String -> IO [Block]
2625
getContent file = do
2726
c <- readFile file
2827
p <- ioReadMarkdown c
29-
return (stripPandoc p)
28+
return $! stripPandoc p
3029

30+
getProcessableFileList :: String -> IO [String]
31+
getProcessableFileList list = do
32+
let f = lines list
33+
let files = filter (\x -> not $ "#" `isPrefixOf` x) f
34+
filterM doesFileExist files
35+
36+
processFiles :: [String] -> IO [Block]
37+
processFiles toProcess =
38+
fmap concat (mapM getContent toProcess)
3139

3240
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]
41+
doInclude (CodeBlock (_, classes, _) list)
42+
| "include" `elem` classes = do
43+
let toProcess = getProcessableFileList list
44+
processFiles =<< toProcess
4945
doInclude x = return [x]
5046

51-
5247
main :: IO ()
5348
main = toJSONFilter doInclude

0 commit comments

Comments
 (0)