Skip to content

Commit ca643c5

Browse files
committed
support include block of source
ex: ```include quote cpp /path/to/your/hello.cpp ```
1 parent 6dc8f15 commit ca643c5

File tree

1 file changed

+27
-4
lines changed

1 file changed

+27
-4
lines changed

IncludeFilter.hs

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,17 +70,40 @@ stripPandoc p =
7070
ioReadMarkdown :: String -> IO(Either PandocError Pandoc)
7171
ioReadMarkdown content = return $! readMarkdown def content
7272

73+
74+
maybeQuote :: String -> Maybe (String, String)
75+
maybeQuote str = case stripPrefix "quote " str of
76+
Just restOfString -> readClsAndFileName $ break (' ' ==) restOfString
77+
Nothing -> Nothing
78+
where readClsAndFileName (cls, ' ':filename) = Just (cls, filename)
79+
readClsAndFileName _ = Nothing
80+
7381
getContent :: String -> IO [Block]
82+
getContent str | Just (cls, file) <- maybeQuote str = do
83+
exists <- doesFileExist file
84+
if exists
85+
then do
86+
c <- readFile file
87+
p <- ioReadMarkdown $ "```" ++ cls ++ "\n" ++ c ++ "\n```\n"
88+
return $! stripPandoc p
89+
else do
90+
return []
7491
getContent file = do
75-
c <- readFile file
76-
p <- ioReadMarkdown c
77-
return $! stripPandoc p
92+
exists <- doesFileExist file
93+
if exists
94+
then do
95+
c <- readFile file
96+
p <- ioReadMarkdown c
97+
return $! stripPandoc p
98+
else do
99+
return []
100+
78101

79102
getProcessableFileList :: String -> IO [String]
80103
getProcessableFileList list = do
81104
let f = lines list
82105
let files = filter (\x -> not $ "#" `isPrefixOf` x) f
83-
filterM doesFileExist files
106+
return files
84107

85108
processFiles :: [String] -> IO [Block]
86109
processFiles toProcess =

0 commit comments

Comments
 (0)