Skip to content

Commit

Permalink
Merge branch 'wcy123-br-support-include-block'
Browse files Browse the repository at this point in the history
  • Loading branch information
steindani committed Mar 26, 2017
2 parents 5090512 + ca643c5 commit 07f32c4
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 11 deletions.
31 changes: 27 additions & 4 deletions IncludeFilter.hs
Original file line number Diff line number Diff line change
Expand Up @@ -70,17 +70,40 @@ stripPandoc p =
ioReadMarkdown :: String -> IO(Either PandocError Pandoc)
ioReadMarkdown content = return $! readMarkdown def content


maybeQuote :: String -> Maybe (String, String)
maybeQuote str = case stripPrefix "quote " str of
Just restOfString -> readClsAndFileName $ break (' ' ==) restOfString
Nothing -> Nothing
where readClsAndFileName (cls, ' ':filename) = Just (cls, filename)
readClsAndFileName _ = Nothing

getContent :: String -> IO [Block]
getContent str | Just (cls, file) <- maybeQuote str = do
exists <- doesFileExist file
if exists
then do
c <- readFile file
p <- ioReadMarkdown $ "```" ++ cls ++ "\n" ++ c ++ "\n```\n"
return $! stripPandoc p
else do
return []
getContent file = do
c <- readFile file
p <- ioReadMarkdown c
return $! stripPandoc p
exists <- doesFileExist file
if exists
then do
c <- readFile file
p <- ioReadMarkdown c
return $! stripPandoc p
else do
return []


getProcessableFileList :: String -> IO [String]
getProcessableFileList list = do
let f = lines list
let files = filter (\x -> not $ "#" `isPrefixOf` x) f
filterM doesFileExist files
return files

processFiles :: [String] -> IO [Block]
processFiles toProcess =
Expand Down
18 changes: 11 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,11 @@ The Code Blocks like the following will include every file in a new line. The
reference paths should be either absolute or relative to the folder where the
pandoc command will be executed.

```markdown
```include
/absolute/file/path.md
relative/to/the/command/root.md
#do/not/include/this.md
```
```
```include
/absolute/file/path.md
relative/to/the/command/root.md
#do/not/include/this.md
```

If the file does not exist, it will be skipped completely. No warnings, no
residue, nothing. Putting an `#` as the first character in the line will make the
Expand Down Expand Up @@ -50,6 +48,12 @@ All this does in the background is pipelining the output of Pandoc and the last
pandoc --from markdown --to json input.md | runhaskell IncludeFilter.hs | pandoc --from json --to latex
```

If using *pandoc-include* together with [*pandoc-citeproc*](https://github.com/jgm/pandoc-citeproc) one has to pay attention to the order of the filters: 1. *pandoc-include*, 2. *pandoc-citeproc*.

```
pandoc -o output.md --filter pandoc-include --filter pandoc-citeproc input.md
```

## License
Copyright ©2015 [Dániel Stein](https://twitter.com/steindani)

Expand Down

0 comments on commit 07f32c4

Please sign in to comment.