aboutsummaryrefslogtreecommitdiff
path: root/tools/specfilter.hs
blob: 7f4df9f9a274e6a0688b6fa4e20f4c72a61be4da (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{-0.4em}\n"
  16. , rawtex "\\begin{minipage}[t]{0.49\\textwidth}\n\\definecolor{shadecolor}{gray}{0.85}\n\\begin{snugshade}\\small\n"
  17. , addBreaks c1
  18. , rawtex "\\end{snugshade}\n\\end{minipage}\n\\hfill\n\\begin{minipage}[t]{0.49\\textwidth}\n\\definecolor{shadecolor}{gray}{0.95}\n\\begin{snugshade}\\small\n"
  19. , addBreaks c2
  20. , rawtex "\\end{snugshade}\n\\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 (Span ("",["number"],[]) xs) = [] -- remove sect numbers
  33. anchors x = [x]