From e6d667e5117ee7277b3844c7900e91809087481c Mon Sep 17 00:00:00 2001 From: Jacob Lifshay Date: Mon, 3 Apr 2023 19:15:53 -0700 Subject: [PATCH] fix pandoc_img hack so source file is always an absolute path --- openpower/pandoc_img.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/openpower/pandoc_img.py b/openpower/pandoc_img.py index 7ecedaee2..d60fac533 100755 --- a/openpower/pandoc_img.py +++ b/openpower/pandoc_img.py @@ -2,6 +2,7 @@ import os import re +import sys import subprocess from pandocfilters import (toJSONFilter, RawInline, Space, Str, walk, Image, Link) @@ -36,12 +37,16 @@ def inlinenotes(k, v, f, meta): 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 + # use absolute paths so pandoc_img.py can be used in any directory + file_path = os.path.abspath(__file__) + openpower_path = os.path.split(file_path)[0] + wiki_path = os.path.split(openpower_path)[0] + imgname = os.path.join(wiki_path, imgname.lstrip('/')) png = imgname.replace(".svg", ".png") png = os.path.split(png)[1] png = "tex_out/%s" % png + print(f"converting {imgname} to {png}", file=sys.stderr) subprocess.run(["inkscape", "-z", "-C", imgname, "--export-png=%s" % png], stdout=subprocess.PIPE) -- 2.30.2