add image and link filtering
authorLuke Kenneth Casson Leighton <lkcl@lkcl.net>
Thu, 30 Jun 2022 14:43:22 +0000 (15:43 +0100)
committerLuke Kenneth Casson Leighton <lkcl@lkcl.net>
Thu, 30 Jun 2022 14:43:22 +0000 (15:43 +0100)
openpower/Makefile
openpower/pandoc_img.py [new file with mode: 0755]
openpower/simple_v_spec.tex

index b43aa030adfe001915c2b1829d222ff597e1bbc5..096fb158b2589d66c23ac764e9fa58f6e0755500 100755 (executable)
@@ -3,11 +3,13 @@
 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
diff --git a/openpower/pandoc_img.py b/openpower/pandoc_img.py
new file mode 100755 (executable)
index 0000000..c207127
--- /dev/null
@@ -0,0 +1,64 @@
+#!/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)
index bab12e16813217a6076163c193e7ecf7292dabec..4cca725e0a87e873c19d436f0d56180391482a93 100644 (file)
@@ -95,11 +95,11 @@ EU Grants 871528 and 957073.
 
 \chapter{Scalable Vectors for the Power ISA}
 \input{tex_out/sv.tex}
-\chapter{Overview}
+\chapter{Overview}\hypertarget{svux2foverview}{Overview}
 \input{tex_out/overview.tex}
 \chapter{Compliancy Levels}
 \input{tex_out/compliancy_levels.tex}
-\chapter{SVP64}
+\chapter{SVP64}\hypertarget{svux2fsvp64}{SVP64}
 \input{tex_out/svp64.tex}
 \chapter{SPRs}
 \input{tex_out/sprs.tex}