Last active
August 29, 2015 14:27
-
-
Save baig/df6bab45f74045fd1bfb to your computer and use it in GitHub Desktop.
A Pandoc filter that replaces code blocks having "notes" class with corresponding Divs.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env runhaskell | |
import Text.Pandoc | |
import Text.Pandoc.Error | |
import Text.Pandoc.JSON | |
import Text.Pandoc.Builder | |
main :: IO () | |
main = toJSONFilter notes | |
notes :: Block -> Block | |
notes (CodeBlock (_,(attr:_),_) str) | |
| attr == "notes" | |
= Div ("", [attr], []) $ toBlocks $ readMarkdown def str | |
notes b = b | |
toBlocks :: Either PandocError Pandoc -> [Block] | |
toBlocks (Left err) = [] | |
toBlocks (Right (Pandoc m bs)) = bs |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
What does it do?
Converts the following pandoc markdown input:
to:
How can I use it?
Install the
pandoc-types
package usingcabal
:Clone this script
Make this script executable.
Now you can use the script as a pandoc filter: