Skip to content

Commit 8d68b4a

Browse files
fixing links and file ids
1 parent 6bc8f02 commit 8d68b4a

File tree

1 file changed

+22
-5
lines changed

1 file changed

+22
-5
lines changed

scripts/transform_doxygen_html.py

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -262,11 +262,24 @@ def find_item_in_dict(k,v,filename):
262262
elif len(v) > 0:
263263
for sk, sv in v.items():
264264
found = find_item_in_dict(sk,sv,filename)
265+
if found == True:
266+
break
265267
except Exception as e:
266268
exc_type, exc_obj, exc_tb = sys.exc_info()
267269
print("ERROR: ", e, exc_tb.tb_lineno)
268270
return found
269271

272+
def make_filename_id(filename):
273+
my_id = filename
274+
try:
275+
my_id = re.sub(".html$", "", my_id)
276+
my_id = re.sub("^group__", "", my_id)
277+
my_id = re.sub("__", "_", my_id)
278+
except Exception as e:
279+
exc_type, exc_obj, exc_tb = sys.exc_info()
280+
print("ERROR: ", e, exc_tb.tb_lineno)
281+
return my_id
282+
270283
def fix_external_links(root, toc_data):
271284
try:
272285
matches = root.xpath(".//a[@href]")
@@ -285,18 +298,21 @@ def fix_external_links(root, toc_data):
285298
if item == filename:
286299
parent_file = item
287300
found = True
301+
break
288302
else:
289303
for k, v in toc_data[item].items():
290304
found = find_item_in_dict(k,v,filename)
291305
if found == True:
292306
parent_file = item
307+
break
308+
if found == True:
309+
break
293310
if parent_file is not None:
294311
parent_file_dest = re.sub("^group__", "", parent_file)
295312
new_href = parent_file_dest
296313
if filename != parent_file:
297314
if target_id is None:
298-
my_id = re.sub(".html$", "", filename)
299-
my_id = re.sub("^group__", "", my_id)
315+
my_id = make_filename_id(filename)
300316
new_href = new_href + "#" + my_id
301317
else:
302318
new_href = new_href + "#" + target_id
@@ -427,9 +443,10 @@ def prep_for_adoc(root):
427443
print("ERROR: ", e, exc_tb.tb_lineno)
428444
return root
429445

430-
def make_adoc(root_string, title_text):
446+
def make_adoc(root_string, title_text, filename):
431447
try:
432-
root_string = "== " + title_text + "\n\n++++\n" + root_string
448+
my_id = make_filename_id(filename)
449+
root_string = "[#"+my_id+"]\n== " + title_text + "\n\n++++\n" + root_string
433450
root_string = re.sub('(<p[^>]+class="adoc-h2"[^>]*>\s*)(.*?)(<\/p>)', '\n++++\n\n=== \\2\n\n++++\n', root_string, flags=re.S)
434451
root_string = re.sub('(<p[^>]+class="adoc-h3"[^>]*>\s*)(.*?)(<\/p>)', '\n++++\n\n==== \\2\n\n++++\n', root_string, flags=re.S)
435452
root_string = root_string + "\n++++\n"
@@ -625,7 +642,7 @@ def handler(html_path, output_path, header_path, output_json):
625642
for child in contents.iterchildren():
626643
final_output = final_output + "\n" + stringify(child)
627644
# prep and write the adoc
628-
adoc = make_adoc(final_output, title_text)
645+
adoc = make_adoc(final_output, title_text, html_file)
629646
adoc_path = re.sub(".html$", ".adoc", this_output_path)
630647
write_output(adoc_path, adoc)
631648
print("Generated " + adoc_path)

0 commit comments

Comments
 (0)