import os
import re
+import sys
import subprocess
from pandocfilters import (toJSONFilter, RawInline, Space, Str, walk, Image,
Link)
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)
find_brack = v.find(']]')
if find_brack == -1:
return
+ hashtag = ""
link = v[2:find_brack]
+ rest = link.split("#") # can be joined up again with '#'.join(rest)
+ link = rest[0]
out.write(" link %s\n" % link)
lookups = {'sv': 'Scalable Vectors for Power ISA',
'SV|sv': 'Scalable Vectors for Power ISA',
'sv/remap': 'REMAP subsystem',
'sv/remap/appendix': 'REMAP Appendix',
'sv/mv.swizzle': 'Swizzle Move',
+ 'sv/twin_butterfly': 'Twin Butterfly',
'sv/mv.vec': 'Pack / Unpack',
'svp64/appendix': 'SVP64 Appendix',
'sv/svp64/appendix': 'SVP64 Appendix',
'openpower/isa/branch': 'Branch pseudocode',
'openpower/transcendentals': 'Transcendentals',
}
+ if link.startswith("ls") and link[2].isdigit():
+ out.write(" found RFC %s\n" % link)
+ return [Link(['', [], []],
+ [Str("{RFC "+link+"}")],
+ ['#%s' % link, '']),
+ Str(v[find_brack+2:])]
if link in lookups:
out.write(" found %s\n" % lookups[link])
return [Link(['', [], []],
[Str("{"+lookups[link]+"}")],
- ['#%s' % link, '']), Str(v[find_brack+2:])]
+ ['#%s' % linklookups(rest), '']),
+ Str(v[find_brack+2:])]
if '|' in link:
link, ref = link.split("|")
return [Link(['', [], []],
[Str(link)],
- [ref, '']), Str(v[find_brack+2:])]
+ [ref, '']),
+ Str(v[find_brack+2:])]
if k == 'Link':
out.write(" link type %s\n" %
(type(v[1][0])))
- if k == 'RawInline' and v[0] == 'html' \
- and re.fullmatch(r"< *br */? *>", v[1]):
- return [RawInline('latex', r'\\')]
+ if k == 'RawInline' and v[0] == 'html':
+ if re.fullmatch(r"< *br */? *>", v[1]):
+ return [RawInline('latex', r'\\')]
+ if re.fullmatch(r"< *sup *>", v[1]):
+ return [RawInline('latex', r'\textsuperscript{')]
+ if re.fullmatch(r"< */ *sup *>", v[1]):
+ return [RawInline('latex', '}')]
+ if re.fullmatch(r"< *sub *>", v[1]):
+ return [RawInline('latex', r'\textsubscript{')]
+ if re.fullmatch(r"< */ *sub *>", v[1]):
+ return [RawInline('latex', '}')]
+ if re.fullmatch(r"< *small *>", v[1]):
+ return [RawInline('latex', r'{\small ')]
+ if re.fullmatch(r"< */ *small *>", v[1]):
+ return [RawInline('latex', '}')]
+def linklookups(rest):
+ res = '#'.join(rest)
+ if len(rest[0]) == 0:
+ res = '_'.join(rest[1:])
+ return res
if __name__ == "__main__":
toJSONFilter(inlinenotes)