aboutsummaryrefslogtreecommitdiff
path: root/specfilter.hs
blob: 67c8fa5ba8728c2fa804fe3fb779b20b5e939e63 (plain)
  1. #!/usr/bin/env runhaskell
  2. import Text.Pandoc.JSON
  3. import Text.Pandoc.Walk
  4. main = toJSONFilter go
  5. where go :: Pandoc -> Pandoc
  6. go = walk exampleDivs . walk anchors
  7. exampleDivs :: Block -> Block
  8. exampleDivs (Div (ident, ["example"], kvs)
  9. [ d@(Div (_,["examplenum"],_) _),
  10. c1@(CodeBlock (_,["markdown"],_) _),
  11. c2@(CodeBlock (_,["html"],_) _)
  12. ]) = Div (ident, ["example"], kvs)
  13. [ rawtex "\\begin{minipage}[t]{\\textwidth}\n{\\scriptsize "
  14. , d
  15. , rawtex "\\vspace{-1em}}"
  16. , rawtex "\\begin{minipage}[t]{0.49\\textwidth}\n\\definecolor{shadecolor}{gray}{0.85}\n"
  17. , addBreaks c1
  18. , rawtex "\\end{minipage}\n\\hfill\n\\begin{minipage}[t]{0.49\\textwidth}\n\\definecolor{shadecolor}{gray}{0.95}\n"
  19. , addBreaks c2
  20. , rawtex "\\end{minipage}\n\\end{minipage}"
  21. ]
  22. where rawtex = RawBlock (Format "latex")
  23. addBreaks (CodeBlock attrs code) = CodeBlock attrs $ addBreaks' code
  24. addBreaks' code =
  25. if length code > 49
  26. then take 49 code ++ ('\n':addBreaks' (drop 49 code))
  27. else code
  28. exampleDivs x = x
  29. anchors :: Inline -> Inline
  30. anchors (RawInline (Format "html") ('<':'a':' ':'i':'d':'=':'"':xs)) =
  31. RawInline (Format "latex") ("\\hyperdef{}{" ++ lab ++ "}{\\label{" ++ lab ++ "}}")
  32. where lab = takeWhile (/='"') xs
  33. anchors x = x