fix pandoc_img hack so source file is always an absolute path
authorJacob Lifshay <programmerjake@gmail.com>
Tue, 4 Apr 2023 02:15:53 +0000 (19:15 -0700)
committerJacob Lifshay <programmerjake@gmail.com>
Tue, 4 Apr 2023 02:28:02 +0000 (19:28 -0700)
openpower/pandoc_img.py

index 7ecedaee2ec51e9847be89f3c186024f5838878c..d60fac53343607d0d568829b6cfca6190d02da96 100755 (executable)
@@ -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)