aboutsummaryrefslogtreecommitdiff
path: root/tools/specfilter.hs
blob: 7a7676b4868b53e2d76510eb9101b79328559956 (plain)
  1. #!/usr/bin/env runhaskell
  2. import Text.Pandoc.JSON
  3. import Text.Pandoc.Generic
  4. main = toJSONFilter go
  5. where go :: Pandoc -> Pandoc
  6. go = bottomUp exampleDivs . bottomUp (concatMap 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 (Link text ('@':lab,_)) =
  31. [RawInline (Format "latex") ("\\hyperdef{}{" ++ lab ++ "}{\\label{" ++ lab ++ "}}"), Strong text]
  32. anchors x = [x]