Skip to content

Instantly share code, notes, and snippets.

@baig
Last active August 29, 2015 14:27
Show Gist options
  • Save baig/df6bab45f74045fd1bfb to your computer and use it in GitHub Desktop.
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.
#!/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
@baig
Copy link
Author

baig commented Aug 22, 2015

What does it do?

Converts the following pandoc markdown input:

# Breakfast

- Eat eggs
- Drink coffee

~~~{.notes}
This is my note.

- It can contain markdown
- like this list
~~~

to:

# Breakfast

- Eat eggs
- Drink coffee

<div class="notes">
This is my note.

- It can contain markdown
- like this list
</div>

How can I use it?

Install the pandoc-types package using cabal:

cabal install pandoc-types

Clone this script

git clone [email protected]:df6bab45f74045fd1bfb.git

Make this script executable.

chmod +x notes.hs

Now you can use the script as a pandoc filter:

pandoc --filter notes.hs your-file.md

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment