summaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorJohn MacFarlane <jgm@berkeley.edu>2015-01-12 20:36:22 -0800
committerJohn MacFarlane <jgm@berkeley.edu>2015-01-12 20:42:30 -0800
commitfed6a57f30ecdbcf4805b1900dd0f164856c1163 (patch)
tree95a4f05799af5f08fe88d50d35d05a5c7a188fae /tools
parent6740322cc41a4f65c1dba81bb4dfe9b8621dc430 (diff)
Moved templates, makespec.py, and specfilter.hs -> tools/.
Diffstat (limited to 'tools')
-rwxr-xr-xtools/specfilter.hs36
1 files changed, 36 insertions, 0 deletions
diff --git a/tools/specfilter.hs b/tools/specfilter.hs
new file mode 100755
index 0000000..7a7676b
--- /dev/null
+++ b/tools/specfilter.hs
@@ -0,0 +1,36 @@
+#!/usr/bin/env runhaskell
+
+import Text.Pandoc.JSON
+import Text.Pandoc.Generic
+
+main = toJSONFilter go
+ where go :: Pandoc -> Pandoc
+ go = bottomUp exampleDivs . bottomUp (concatMap anchors)
+
+exampleDivs :: Block -> Block
+exampleDivs (Div (ident, ["example"], kvs)
+ [ d@(Div (_,["examplenum"],_) _),
+ c1@(CodeBlock (_,["markdown"],_) _),
+ c2@(CodeBlock (_,["html"],_) _)
+ ]) = Div (ident, ["example"], kvs)
+ [ rawtex "\\begin{minipage}[t]{\\textwidth}\n{\\scriptsize "
+ , d
+ , rawtex "\\vspace{-1em}}"
+ , rawtex "\\begin{minipage}[t]{0.49\\textwidth}\n\\definecolor{shadecolor}{gray}{0.85}\n"
+ , addBreaks c1
+ , rawtex "\\end{minipage}\n\\hfill\n\\begin{minipage}[t]{0.49\\textwidth}\n\\definecolor{shadecolor}{gray}{0.95}\n"
+ , addBreaks c2
+ , rawtex "\\end{minipage}\n\\end{minipage}"
+ ]
+ where rawtex = RawBlock (Format "latex")
+ addBreaks (CodeBlock attrs code) = CodeBlock attrs $ addBreaks' code
+ addBreaks' code =
+ if length code > 49
+ then take 49 code ++ ('\n':addBreaks' (drop 49 code))
+ else code
+exampleDivs x = x
+
+anchors :: Inline -> [Inline]
+anchors (Link text ('@':lab,_)) =
+ [RawInline (Format "latex") ("\\hyperdef{}{" ++ lab ++ "}{\\label{" ++ lab ++ "}}"), Strong text]
+anchors x = [x]