bug 1034: making room for crfbinlog/crfternlogi/crbinlog/crternlogi
[libreriscv.git] / openpower / mdwn_inline.py
index c0738b353f7a7802b7f9c3fd75da8bffda030f6a..6dec26a8b14052c1a2012116b53016b6d43fe432 100755 (executable)
@@ -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 <a name="%s"> </>\n' % (line.strip(), l)
         # find actual inlines
         if not line.startswith("[[!inline"):
             o.write(line)
@@ -69,13 +80,16 @@ def recursive_inline(f, input_name, depth):
             if fname.endswith(".mdwn"):
                 with open_tracked(wiki_path + "/" + fname) as inc:
                     recursive_inline(inc, fname, depth + 1)
-            elif fname == 'openpower/isatables/fields.text':
-                with open_tracked(
-                        wiki_path + "/../openpower-isa/" + fname) as inc:
+            elif fname.startswith('openpower/isatables'):
+                pth = wiki_path + "/../openpower-isa/" + fname
+                with open_tracked(pth) as inc:
+                    recursive_inline(inc, fname, depth + 1)
+            elif fname.startswith('openpower/isa'):
+                pth = wiki_path + "/../openpower-isa/" + fname + ".mdwn"
+                with open_tracked(pth) as inc:
                     recursive_inline(inc, fname, depth + 1)
             else:
-                with open_tracked(
-                        wiki_path + "/" + fname + ".mdwn") as inc:
+                with open_tracked(wiki_path + "/" + fname + ".mdwn") as inc:
                     recursive_inline(inc, fname, depth + 1)