From: Luke Kenneth Casson Leighton Date: Thu, 1 Jun 2023 14:34:43 +0000 (+0100) Subject: add link-lookups into mdwn_inline.py and pandoc_img.py X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=7cce2ccf9e613714cd1c15408e0faf59576af585;p=libreriscv.git add link-lookups into mdwn_inline.py and pandoc_img.py attempting to be able to do cross-referencing automatically, involves headers "# " automatically gaining an tag --- diff --git a/openpower/mdwn_inline.py b/openpower/mdwn_inline.py index efabb12ce..2c03ae22c 100755 --- a/openpower/mdwn_inline.py +++ b/openpower/mdwn_inline.py @@ -48,6 +48,17 @@ def recursive_inline(f, input_name, depth): o.write(line) o.write("\\itemsep -0.3em\n") continue + # find headings and create name-refs, including filename + if line.startswith("#"): + iname = input_name.split("/") + if iname[0] == 'openpower': iname.pop(0) + l = line.strip().split(" ")[1:3] + l = map(lambda x: ''.join(filter(str.isalnum, x)), l) + l = map(str.lower, l) + l = filter(lambda x:x, l) + l = list(dict.fromkeys(iname + list(l))) + l = '_'.join(l) + line = '%s \n' % (line.strip(), l) # find actual inlines if not line.startswith("[[!inline"): o.write(line) diff --git a/openpower/pandoc_img.py b/openpower/pandoc_img.py index 5fb6745bb..f2f19f39f 100755 --- a/openpower/pandoc_img.py +++ b/openpower/pandoc_img.py @@ -59,7 +59,10 @@ def inlinenotes(k, v, f, meta): 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', @@ -107,17 +110,20 @@ def inlinenotes(k, v, f, meta): out.write(" found RFC %s\n" % link) return [Link(['', [], []], [Str("{RFC "+link+"}")], - ['#%s' % link, '']), Str(v[find_brack+2:])] + ['#%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]))) @@ -137,6 +143,11 @@ def inlinenotes(k, v, f, meta): 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)