1414# TO DO:
1515# do internal href links need to be updated?
1616
17+ def add_next_with_tail (target , inserted ):
18+ if target .tail is not None :
19+ inserted .tail = inserted .tail + target .tail if inserted .tail is not None else target .tail
20+ target .tail = None
21+ target .addnext (inserted )
22+
1723def get_all_text (node ):
1824 text = node .text if node .text else None
1925 if text :
@@ -69,7 +75,7 @@ def make_attribute_selector(sel, item):
6975 if "*" in att_value :
7076 contains = True
7177 if contains == True :
72- val = re .sub ("\*" , "" , " " .join (att ["value" ]))
78+ val = re .sub (r "\*" , "" , " " .join (att ["value" ]))
7379 atts .append ("contains(@" + att ["name" ] + ",'" + val + "')" )
7480 else :
7581 # otherwise it's a normal attribute selector
@@ -200,16 +206,16 @@ def transform_element(item, root, is_child=False):
200206 # set attributes, add text/tail, and add children
201207 new_tree = add_content_to_tree (new_tree , match )
202208 # add the new tree to the document
203- match . addnext ( new_tree )
209+ add_next_with_tail ( match , new_tree )
204210 # remove the old element
205211 match .getparent ().remove (match )
206212 else :
207213 # if there is no tree, the element should be removed
208214 # first, preserve any children:
209215 for child in reversed (match .findall ("./*" )):
210- match . addnext ( child )
216+ add_next_with_tail ( match , child )
211217 # handle the tail if needed
212- if match .tail is not None and re .search ("\S" , match .tail ) is not None :
218+ if match .tail is not None and re .search (r "\S" , match .tail ) is not None :
213219 prev = match .getprevious ()
214220 if prev is not None :
215221 prev .tail = prev .tail + match .tail if prev .tail is not None else match .tail
@@ -309,7 +315,7 @@ def find_item_in_toc(h_json, filename):
309315
310316def fix_external_links (adoc , h_json ):
311317 try :
312- matches = re .findall ("(href=[\" '])([^\s>]*?)([\" '])" , adoc )
318+ matches = re .findall (r "(href=[\"'])([^\s>]*?)([\"'])" , adoc )
313319 for match in matches :
314320 href = match [1 ]
315321 # href = match.get("href")
@@ -452,7 +458,7 @@ def retag_heading(head, headtype):
452458 else :
453459 newel .set ("id" , head .get ("id" ))
454460 newel .text = text
455- head . addnext ( newel )
461+ add_next_with_tail ( head , newel )
456462 head .getparent ().remove (head )
457463 except Exception as e :
458464 exc_type , exc_obj , exc_tb = sys .exc_info ()
@@ -475,11 +481,11 @@ def prep_for_adoc(root):
475481def make_adoc (root_string , title_text , filename ):
476482 try :
477483 my_id = make_filename_id (filename )
478- root_string = re .sub ("<\/div>\s*?$" , "" , root_string , flags = re .S )
479- root_string = re .sub ('<div class="contents" id="\S*?">' , "" , root_string )
484+ root_string = re .sub (r "<\/div>\s*?$" , "" , root_string , flags = re .S )
485+ root_string = re .sub (r '<div class="contents" id="\S*?">' , "" , root_string )
480486 root_string = "[[" + my_id + "]]\n == " + title_text + "\n \n ++++\n " + root_string
481- root_string = re .sub ('(<p[^>]+class="adoc-h2"[^>]*id=")([^"]+)("[^>]*>\s*)(.*?)(<\/p>)' , '\n ++++\n \n [[\\ 2]]\n === \\ 4\n \n ++++\n ' , root_string , flags = re .S )
482- root_string = re .sub ('(<p[^>]+class="adoc-h3"[^>]*id=")([^"]+)("[^>]*>\s*)(.*?)(<\/p>)' , '\n ++++\n \n [[\\ 2]]\n ==== \\ 4\n \n ++++\n ' , root_string , flags = re .S )
487+ root_string = re .sub (r '(<p[^>]+class="adoc-h2"[^>]*id=")([^"]+)("[^>]*>\s*)(.*?)(<\/p>)' , '\n ++++\n \n [[\\ 2]]\n === \\ 4\n \n ++++\n ' , root_string , flags = re .S )
488+ root_string = re .sub (r '(<p[^>]+class="adoc-h3"[^>]*id=")([^"]+)("[^>]*>\s*)(.*?)(<\/p>)' , '\n ++++\n \n [[\\ 2]]\n ==== \\ 4\n \n ++++\n ' , root_string , flags = re .S )
483489 root_string = root_string + "\n ++++\n "
484490 except Exception as e :
485491 exc_type , exc_obj , exc_tb = sys .exc_info ()
@@ -488,7 +494,7 @@ def make_adoc(root_string, title_text, filename):
488494
489495def decrease_heading_levels (adoc ):
490496 try :
491- adoc = re .sub ("\n ==" , "\n =" , adoc , flags = re .S )
497+ adoc = re .sub (r "\n==" , "\n =" , adoc , flags = re .S )
492498 except Exception as e :
493499 exc_type , exc_obj , exc_tb = sys .exc_info ()
494500 print ("ERROR: " , e , exc_tb .tb_lineno )
@@ -521,29 +527,29 @@ def parse_header(header_path):
521527 try :
522528 with open (header_path ) as h :
523529 content = h .read ()
524- blocks = re .findall ("^(\s*)(\*|\/\*\*)(\s*)(\s)(\*)(\s)(\\ \\ )(defgroup)([^}]*)(\@\})" , content , re .M )
530+ blocks = re .findall (r "^(\s*)(\*|\/\*\*)(\s*)(\s)(\*)(\s)(\\)(defgroup)([^}]*)(\@\})" , content , re .M )
525531 for (a , b , c , d , e , f , g , h , i , j ) in blocks :
526- items = i .split ("\defgroup" )
532+ items = i .split (r "\defgroup" )
527533 group_id = None
528534 for item in items :
529535 if group_id is None : # must be the first item in the list
530- m = re .match ("(\s*)(\S*)(\s*)([^*]*)(.*?)(@\{)" , item , re .S )
536+ m = re .match (r "(\s*)(\S*)(\s*)([^*]*)(.*?)(@\{)" , item , re .S )
531537 group_id = m .group (2 )
532538 group_filename = "group_" + group_id + ".html"
533539 group_filename = re .sub ("_" , "__" , group_filename )
534540 group_name = m .group (4 )
535- group_name = re .sub ("\s*$" , "" , group_name , re .M )
541+ group_name = re .sub (r "\s*$" , "" , group_name , re .M )
536542 group_desc = m .group (5 )
537- group_desc = re .sub ("\n " , "" , group_desc , re .M )
538- group_desc = re .sub ("\*" , "" , group_desc , re .M )
539- group_desc = re .sub ("^\s" , "" , group_desc , re .M )
543+ group_desc = re .sub (r "\n" , "" , group_desc , re .M )
544+ group_desc = re .sub (r "\*" , "" , group_desc , re .M )
545+ group_desc = re .sub (r "^\s" , "" , group_desc , re .M )
540546 group_json = { 'group_id' : group_id , 'name' : group_name , 'description' : group_desc , 'html' : group_filename , 'subitems' : [] }
541547 h_json .append (group_json )
542548 else :
543549 cleaned = item
544- cleaned = re .sub ("\n *" , "" , cleaned , re .M )
545- cleaned = re .sub ("^\s*" , "" , cleaned , re .M )
546- cleaned = re .sub ("\s*\*\s*$" , "" , cleaned , re .M )
550+ cleaned = re .sub (r "\n*" , "" , cleaned , re .M )
551+ cleaned = re .sub (r "^\s*" , "" , cleaned , re .M )
552+ cleaned = re .sub (r "\s*\*\s*$" , "" , cleaned , re .M )
547553 val = cleaned .split (" " )[0 ]
548554 filename = re .sub ("_" , "__" , val )
549555 filename = "group__" + filename
@@ -705,12 +711,12 @@ def parse_individual_file(html_path, html_file, complete_json_mappings, updated_
705711 # read the input root
706712 with open (this_path ) as h :
707713 html_content = h .read ()
708- html_content = re .sub ('<\!DOCTYPE html PUBLIC "-\/\/W3C\/\/DTD XHTML 1\.0 Transitional\/\/EN" "https:\/\/www\.w3\.org\/TR\/xhtml1\/DTD\/xhtml1-transitional\.dtd">' , '' , html_content )
714+ html_content = re .sub (r '<\!DOCTYPE html PUBLIC "-\/\/W3C\/\/DTD XHTML 1\.0 Transitional\/\/EN" "https:\/\/www\.w3\.org\/TR\/xhtml1\/DTD\/xhtml1-transitional\.dtd">' , '' , html_content )
709715 html_content = re .sub ('rel="stylesheet">' , 'rel="stylesheet"/>' , html_content )
710716 html_content = re .sub ('&display=swap"' , '"' , html_content )
711- html_content = re .sub ('<img src="logo-mobile\.svg" alt="Raspberry Pi">' , '' , html_content )
712- html_content = re .sub ('<img src="logo\.svg" alt="Raspberry Pi">' , '' , html_content )
713- html_content = re .sub ("<\!-- HTML header for doxygen \S*?-->" , '' , html_content )
717+ html_content = re .sub (r '<img src="logo-mobile\.svg" alt="Raspberry Pi">' , '' , html_content )
718+ html_content = re .sub (r '<img src="logo\.svg" alt="Raspberry Pi">' , '' , html_content )
719+ html_content = re .sub (r "<\!-- HTML header for doxygen \S*?-->" , '' , html_content )
714720 html_content = re .sub (' xmlns="http://www.w3.org/1999/xhtml"' , '' , html_content )
715721 root = etree .HTML (html_content )
716722
0 commit comments