tex:
mkdir -p tex_out
pandoc -f markdown -t latex --top-level-division=section \
+ --filter pandoc_img.py \
-N -o tex_out/sv.tex sv.mdwn
pandoc -f markdown -t latex --top-level-division=section \
--filter pandoc_img.py \
-N -o tex_out/overview.tex sv/overview.mdwn
pandoc -f markdown -t latex --top-level-division=section \
+ --filter pandoc_img.py \
-N -o tex_out/svp64.tex sv/svp64.mdwn
pandoc -f markdown -t latex --top-level-division=section \
-N -o tex_out/svp64_appendix.tex sv/svp64/appendix.mdwn
--- /dev/null
+#!/usr/bin/env python3
+
+import os
+import subprocess
+from pandocfilters import (toJSONFilter, RawInline, Space, Str, walk, Image,
+ Link)
+
+"""
+Pandoc filter for Markdown that converts most endnotes into
+Pandoc's inline notes. If input notes had multiple paragraphs,
+the paragraphs are joined by a space. But if an input note
+had any blocks other than paragraphs, the note is left as is.
+"""
+
+#inkscape -z sv/bridge_phy.svg --export-png=bridge.png
+out = open("/tmp/log.txt", "w")
+
+def query(k, v, f, meta):
+ global inlines
+ if k == 'BlockQuote':
+ inlines.append(v)
+ elif isinstance(v, list):
+ if inlines and k == 'Para':
+ inlines.append(Space())
+ inlines.extend(v)
+ return v
+
+def inlinenotes(k, v, f, meta):
+ out.write("k v f meta %s %s %s %s\n" % \
+ (repr(k), repr(v), repr(f), repr(meta)))
+ global inlines
+ inlines = []
+ if k == u'Image' and f == 'latex':
+ imgname = v[2][0]
+ out.write(" image %s\n" % (imgname))
+ # HACK! works only relative to openpower directory!
+ if imgname.startswith("/"):
+ imgname = ".." + imgname
+ png = imgname.replace(".svg", ".png")
+ png = os.path.split(png)[1]
+ png = "tex_out/%s" % png
+ subprocess.run(["inkscape", "-z", "-C", imgname,
+ "--export-png=%s" % png],
+ stdout=subprocess.PIPE)
+ v[2][0] = png
+ return Image(*v)
+ if k == 'Str' and f == 'latex':
+ # link page
+ if v.startswith("[[") and v.endswith("]]"):
+ link = v[2:-2]
+ lookups = {'sv/overview': 'Overview Chapter',
+ 'sv/svp64': 'SVP64 Chapter',
+ }
+ if link in lookups:
+ return Link(['', [], []],
+ [Str(lookups[link])],
+ ['#%s' % link, ''])
+ if k == 'Link':
+ out.write(" link type %s\n" % \
+ (type(v[1][0])))
+
+
+if __name__ == "__main__":
+ toJSONFilter(inlinenotes)