@@ -262,11 +262,24 @@ def find_item_in_dict(k,v,filename):
262
262
elif len (v ) > 0 :
263
263
for sk , sv in v .items ():
264
264
found = find_item_in_dict (sk ,sv ,filename )
265
+ if found == True :
266
+ break
265
267
except Exception as e :
266
268
exc_type , exc_obj , exc_tb = sys .exc_info ()
267
269
print ("ERROR: " , e , exc_tb .tb_lineno )
268
270
return found
269
271
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
+
270
283
def fix_external_links (root , toc_data ):
271
284
try :
272
285
matches = root .xpath (".//a[@href]" )
@@ -285,18 +298,21 @@ def fix_external_links(root, toc_data):
285
298
if item == filename :
286
299
parent_file = item
287
300
found = True
301
+ break
288
302
else :
289
303
for k , v in toc_data [item ].items ():
290
304
found = find_item_in_dict (k ,v ,filename )
291
305
if found == True :
292
306
parent_file = item
307
+ break
308
+ if found == True :
309
+ break
293
310
if parent_file is not None :
294
311
parent_file_dest = re .sub ("^group__" , "" , parent_file )
295
312
new_href = parent_file_dest
296
313
if filename != parent_file :
297
314
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 )
300
316
new_href = new_href + "#" + my_id
301
317
else :
302
318
new_href = new_href + "#" + target_id
@@ -427,9 +443,10 @@ def prep_for_adoc(root):
427
443
print ("ERROR: " , e , exc_tb .tb_lineno )
428
444
return root
429
445
430
- def make_adoc (root_string , title_text ):
446
+ def make_adoc (root_string , title_text , filename ):
431
447
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
433
450
root_string = re .sub ('(<p[^>]+class="adoc-h2"[^>]*>\s*)(.*?)(<\/p>)' , '\n ++++\n \n === \\ 2\n \n ++++\n ' , root_string , flags = re .S )
434
451
root_string = re .sub ('(<p[^>]+class="adoc-h3"[^>]*>\s*)(.*?)(<\/p>)' , '\n ++++\n \n ==== \\ 2\n \n ++++\n ' , root_string , flags = re .S )
435
452
root_string = root_string + "\n ++++\n "
@@ -625,7 +642,7 @@ def handler(html_path, output_path, header_path, output_json):
625
642
for child in contents .iterchildren ():
626
643
final_output = final_output + "\n " + stringify (child )
627
644
# prep and write the adoc
628
- adoc = make_adoc (final_output , title_text )
645
+ adoc = make_adoc (final_output , title_text , html_file )
629
646
adoc_path = re .sub (".html$" , ".adoc" , this_output_path )
630
647
write_output (adoc_path , adoc )
631
648
print ("Generated " + adoc_path )
0 commit comments