From a1dc08964d8a817f45752467f1d5bf6d1252ef92 Mon Sep 17 00:00:00 2001 From: Luke Kenneth Casson Leighton Date: Thu, 30 Jun 2022 15:43:22 +0100 Subject: [PATCH] add image and link filtering --- openpower/Makefile | 2 ++ openpower/pandoc_img.py | 64 +++++++++++++++++++++++++++++++++++++ openpower/simple_v_spec.tex | 4 +-- 3 files changed, 68 insertions(+), 2 deletions(-) create mode 100755 openpower/pandoc_img.py diff --git a/openpower/Makefile b/openpower/Makefile index b43aa030a..096fb158b 100755 --- a/openpower/Makefile +++ b/openpower/Makefile @@ -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 index 000000000..c2071276c --- /dev/null +++ b/openpower/pandoc_img.py @@ -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) diff --git a/openpower/simple_v_spec.tex b/openpower/simple_v_spec.tex index bab12e168..4cca725e0 100644 --- a/openpower/simple_v_spec.tex +++ b/openpower/simple_v_spec.tex @@ -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} -- 2.30.2