Created
January 4, 2015 01:52
-
-
Save mpickering/c518863fa193ac075042 to your computer and use it in GitHub Desktop.
Pandoc filter to render frames around content
This file contains 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
{-# LANGUAGE OverloadedStrings #-} | |
module Main where | |
-- https://groups.google.com/d/msgid/pandoc-discuss/45a32eb9-23b9-4df1-8c6e-2e08073df166%40googlegroups.com?utm_medium=email&utm_source=footer | |
import Text.Pandoc.JSON | |
import Text.Pandoc.Definition | |
import Text.Printf | |
import Data.Maybe | |
main :: IO () | |
main = toJSONFilter findFrame | |
defaultDisplayStyle :: String | |
defaultDisplayStyle = "frame" | |
defaultTitle :: String | |
defaultTitle = "" | |
findFrame :: Block -> Block | |
findFrame e@(Div as@(uid, classes, kvs) is) | |
| "frame" `elem` classes = | |
let displayStyle = fromMaybe defaultDisplayStyle (lookup "style" kvs) | |
frameTitle = fromMaybe defaultTitle (lookup "title" kvs) in | |
Div as ([mkEnv displayStyle frameTitle] ++ is ++ [closeEnv]) | |
| otherwise = e | |
findFrame e = e | |
mkEnv :: String -> String -> Block | |
mkEnv st tit = RawBlock "latex" $ printf "\\begin{mdframed}[style={%s},frametitle={%s}]" st tit | |
closeEnv :: Block | |
closeEnv = RawBlock "latex" "\\end{mdframed}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment