Skip to content

Commit 5b168ed

Browse files
committed
Restructure, Cabal package
1 parent bb4ca08 commit 5b168ed

File tree

12 files changed

+199
-9
lines changed

12 files changed

+199
-9
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
dist/
2+
.idea
3+
*.iml

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Changelog
2+
3+
## v0.0.1 – 2015-12-08
4+
* Project restructured
5+
* License
6+
* Initial documentation
7+
* Cabal package file

IncludeFilter.hs

Lines changed: 57 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,65 @@
11
#!/usr/bin/env runhaskell
2-
-- includes.hs
32

4-
module Text.Pandoc.Include where
3+
{-
4+
The MIT License (MIT)
55
6-
import Control.Monad
7-
import Data.List
8-
import System.Directory
6+
Copyright (c) 2015 Dániel Stein <[email protected]>
97
10-
import Text.Pandoc.JSON
11-
import Text.Pandoc
12-
import Text.Pandoc.Error
8+
Permission is hereby granted, free of charge, to any person obtaining
9+
a copy of this software and associated documentation files (the
10+
"Software"), to deal in the Software without restriction, including
11+
without limitation the rights to use, copy, modify, merge, publish,
12+
distribute, sublicense, and/or sell copies of the Software, and to
13+
permit persons to whom the Software is furnished to do so, subject to
14+
the following conditions:
1315
16+
The above copyright notice and this permission notice shall be included
17+
in all copies or substantial portions of the Software.
18+
19+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
20+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
21+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
22+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
23+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
24+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
25+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26+
-}
27+
28+
{-|
29+
A Pandoc filter that replaces include labeled Code Blocks with the contents of
30+
the referenced files. Even nested, recursive includes.
31+
32+
Based on the scripting tutorial for Pandoc:
33+
http://pandoc.org/scripting.html#include-files
34+
35+
The Code Blocks like the following will include every file in a new line. The
36+
reference paths should be either absolute or relative to the folder where the
37+
pandoc command will be executed.
38+
39+
> ```include
40+
> /absolute/file/path.md
41+
> relative/to/the/command/root.md
42+
> #do/not/include/this.md
43+
> ```
44+
45+
If the file does not exist, it will be skipped completely. No warnings, no
46+
residue, nothing. Putting an # as the first character in the line will make the
47+
filter skip that file.
48+
49+
For now the nested includes only work for two levels, after that the source
50+
will be inserted and not parsed.
51+
52+
Note: the metadata from the included source files are discarded.
53+
54+
-}
55+
56+
import Control.Monad
57+
import Data.List
58+
import System.Directory
59+
60+
import Text.Pandoc
61+
import Text.Pandoc.Error
62+
import Text.Pandoc.JSON
1463

1564
stripPandoc :: Either PandocError Pandoc -> [Block]
1665
stripPandoc p =

LICENSE

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) 2015 Dániel Stein <[email protected]>
4+
5+
6+
Permission is hereby granted, free of charge, to any person obtaining
7+
a copy of this software and associated documentation files (the
8+
"Software"), to deal in the Software without restriction, including
9+
without limitation the rights to use, copy, modify, merge, publish,
10+
distribute, sublicense, and/or sell copies of the Software, and to
11+
permit persons to whom the Software is furnished to do so, subject to
12+
the following conditions:
13+
14+
The above copyright notice and this permission notice shall be included
15+
in all copies or substantial portions of the Software.
16+
17+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
20+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
21+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
22+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
23+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

README.md

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
# pandoc-include
2+
A Pandoc filter that replaces include labeled Code Blocks with the contents of
3+
the referenced files. Even nested, recursive includes.
4+
5+
Based on the scripting tutorial for Pandoc:
6+
http://pandoc.org/scripting.html#include-files
7+
8+
## Format
9+
The Code Blocks like the following will include every file in a new line. The
10+
reference paths should be either absolute or relative to the folder where the
11+
pandoc command will be executed.
12+
13+
`````
14+
```include
15+
/absolute/file/path.md
16+
relative/to/the/command/root.md
17+
#do/not/include/this.md
18+
```
19+
`````
20+
21+
If the file does not exist, it will be skipped completely. No warnings, no
22+
residue, nothing. Putting an `#` as the first character in the line will make the
23+
filter skip that file.
24+
25+
For now the nested includes only work for two levels, after that the source
26+
will be inserted and not parsed.
27+
28+
*Note: the metadata from the included source files are discarded.*
29+
30+
## Installation
31+
One could either install it using the Cabal packaging system by running:
32+
33+
```
34+
cabal update
35+
cabal install pandoc-include
36+
```
37+
38+
Or it is also possible to use the pipe method using the source code described in the *Usage* section.
39+
40+
## Usage
41+
In order to use this Pandoc filter, one has to include it into the Pandoc transformation workflow. This can be done by using the `--filter` parameter, like so:
42+
43+
```
44+
pandoc --from markdown --to latex --filter pandoc-include input.md
45+
```
46+
47+
All this does in the background is pipelining the output of Pandoc and the last filter into the standard input of the include filter and using its output as the next filter's input:
48+
49+
```
50+
pandoc --from markdown --to json input.md | runhaskell IncludeFilter.hs | pandoc --from json --to latex
51+
```
52+
53+
## License
54+
Copyright ©2015 [Dániel Stein](https://twitter.com/steindani)
55+
56+
Source code is released under the Terms and Conditions of [MIT License](http://opensource.org/licenses/MIT).

Setup.hs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
import Distribution.Simple
2+
main = defaultMain

beta.md

Lines changed: 0 additions & 1 deletion
This file was deleted.

pandoc-include.cabal

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
Name: pandoc-include
2+
Version: 0.0.1
3+
Synopsis: Include other Markdown files
4+
Description: A Pandoc filter that replaces include labeled
5+
Code Blocks with the contents of the referenced
6+
Markdown files. Even nested, recursive includes.
7+
Homepage: https://github.com/steindani/pandoc-include
8+
Bug-Reports: https://github.com/steindani/pandoc-include/issues
9+
License: MIT
10+
License-File: LICENSE
11+
Author: Dániel Stein <[email protected]>
12+
Maintainer: Dániel Stein <[email protected]>
13+
Copyright: (c) 2015 Dániel Stein
14+
Stability: alpha
15+
Category: Text
16+
Build-Type: Simple
17+
Data-Files: README.md
18+
Extra-Source-Files: CHANGELOG.md
19+
Cabal-Version: >=1.10
20+
Source-repository head
21+
type: git
22+
location: git://github.com/steindani/pandoc-include.git
23+
24+
Library
25+
Build-Depends: base >= 4.6 && < 5,
26+
text >= 0.11,
27+
pandoc >= 1.13.0.0,
28+
pandoc-types >= 1.12.0.0,
29+
directory
30+
Hs-Source-Dirs: src
31+
Default-Extensions: CPP
32+
Exposed-Modules:
33+
Buildable: True
34+
Default-Language: Haskell2010
35+
36+
Executable pandoc-include
37+
Build-Depends: base >= 4.6,
38+
text >= 0.11,
39+
pandoc >= 1.13.0.0,
40+
pandoc-types >= 1.12.0.0,
41+
directory
42+
Hs-Source-Dirs: .
43+
Main-Is: IncludeFilter.hs
44+
Buildable: True
45+
Default-Language: Haskell2010
File renamed without changes.

test/beta.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
BETA!!!
2+
3+
```include
4+
gamma.md
5+
```

0 commit comments

Comments
 (0)