summaryrefslogtreecommitdiff
path: root/specfilter.hs
diff options
context:
space:
mode:
authorJohn MacFarlane <jgm@berkeley.edu>2014-07-21 22:29:16 -0700
committerJohn MacFarlane <jgm@berkeley.edu>2014-08-13 22:56:32 -0700
commit870e63be7360b5a0097a27656048e853bc720464 (patch)
treee8f19ee2d62e529115cb71dcda5f3298cca7d389 /specfilter.hs
parent650ad87f35f4405a2ca8270d2b2835daa442e5f1 (diff)
Initial commit
Diffstat (limited to 'specfilter.hs')
-rwxr-xr-xspecfilter.hs37
1 files changed, 37 insertions, 0 deletions
diff --git a/specfilter.hs b/specfilter.hs
new file mode 100755
index 0000000..67c8fa5
--- /dev/null
+++ b/specfilter.hs
@@ -0,0 +1,37 @@
+#!/usr/bin/env runhaskell
+
+import Text.Pandoc.JSON
+import Text.Pandoc.Walk
+
+main = toJSONFilter go
+ where go :: Pandoc -> Pandoc
+ go = walk exampleDivs . walk 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 (RawInline (Format "html") ('<':'a':' ':'i':'d':'=':'"':xs)) =
+ RawInline (Format "latex") ("\\hyperdef{}{" ++ lab ++ "}{\\label{" ++ lab ++ "}}")
+ where lab = takeWhile (/='"') xs
+anchors x = x