- Timestamp:
- Mar 9, 2023 12:25:18 PM (2 years ago)
- svn:sync-xref-src-repo-rev:
- 156227
- Location:
- trunk/doc/manual
- Files:
-
- 1 edited
- 1 copied
Legend:
- Unmodified
- Added
- Removed
-
trunk/doc/manual/Makefile.kmk
r98892 r98893 859 859 860 860 $$(QUIET)$$(RM) -f "$$@" 861 $$(QUIET)$$( call VBOX_XSLTPROC_WITH_CAT) --maxdepth 6000 --output $$(VBOX_PATH_MANUAL_OUTBASE)/$(1)/dita/topics/$(2) $(VBOX_PATH_MANUAL_SRC)/refsect2_replace.xsl $$(VBOX_PATH_MANUAL_SRC)/$(1)/$(2)861 $$(QUIET)$$(VBOX_BLD_PYTHON) $$(VBOX_PATH_MANUAL_SRC)/refsect2_to_refsect1.py -i $$(VBOX_PATH_MANUAL_SRC)/$(1)/$(2) -o $$(VBOX_PATH_MANUAL_OUTBASE)/$(1)/dita/topics/$(2) 862 862 $$(call MSG_TOOL,xsltproc $$(notdir $$(firstword $$(filter %.xsl,$$^))),,$$(firstword $$(filter %.xml,$$^)),$$@) 863 863 $$(QUIET)$$(call VBOX_XSLTPROC_WITH_CAT) --maxdepth 6000 --output $$@ $$(VBOX_DITA_CONVERTER_PATH)/db2dita/docbook2dita.xsl $$(VBOX_PATH_MANUAL_OUTBASE)/$(1)/dita/topics/$(2) -
trunk/doc/manual/refsect2_to_refsect1.py
r98881 r98893 38 38 """ 39 39 40 """ 41 key is the id, value is the name of the containing file. 42 """ 43 xref_dictionary = {} 40 def replaceRefsect2(file_content): 41 new_content = [] 42 """ 43 * Add a refsect1 before the first refsect2, 44 * convert refsect2 to refsect1, 45 * remove the </refsect1> which comes after a </refsect2> 46 """ 47 first_refsect2 = False 48 # remove lines that consist of new line only 49 file_content = [line for line in file_content if line != "\n"] 50 new_content.append(file_content[0]) 51 for current, next in zip(file_content, file_content[1:]): 44 52 45 """" 46 ================================================================= 47 Cross reference utility functions to add file name to target name. 48 ================================================================= 49 """ 50 # Search for hrefs and return a tuple where 0th element is target and 1st element is its index in @p line 51 def extractHrefTarget(line, start = 0): 52 target = "" 53 pointer0 = line.find("href=\"", start) 54 if pointer0 == -1: 55 return (target, -1) 56 pointer0 += len("href=\"") 57 pointer1 = line.find("\"", pointer0) 58 if pointer1 == -1: 59 return (target, -1) 60 return (line[pointer0:pointer1], pointer0) 53 if "<refsect2" in next: 54 if not first_refsect2: 55 first_refsect2 = True 56 new_content.append("</refsect1>") 57 new_content.append("\n") 58 new_content.append(next.replace("<refsect2", "<refsect1")) 59 elif "</refsect2>" in next: 60 new_content.append("</refsect1>") 61 new_content.append("\n") 62 elif not ("</refsect1>" in next and "</refsect2>" in current): 63 new_content.append(next) 64 return new_content 61 65 62 # Return list of href targets contained in @p line63 def extractHrefList(line):64 targets = []65 index = 066 while index < len(line):67 ttarget = extractHrefTarget(line, index)68 index = ttarget[1]69 if index == -1:70 break71 targets.append(ttarget[0])72 return targets73 74 def correctHrefTargets(file_content):75 for idx, line in enumerate(file_content):76 if "href" in line:77 targets = extractHrefList(line)78 newline = line79 for target in targets:80 if target in xref_dictionary and os.path.basename != xref_dictionary[target]:81 old = "\"" + target + "\""82 new = "\"" + xref_dictionary[target] + "#" + target + "\""83 newline = newline.replace(old, new)84 file_content[idx] = newline85 86 def createXrefIdDictionary(ditafolder):87 xref_dictionary.clear()88 dita_files = glob.glob(ditafolder + "/*.dita")89 for file in dita_files:90 file_content = open(file, 'r', encoding="utf-8")91 for line in file_content:92 if "reference" in line or "topic" in line or "section" in line:93 start = line.find("id=\"")94 if start != -1:95 start += len("id=\"")96 end = line.find("\"", start)97 if end != -1:98 id = line[start:end]99 if len(id) > 0:100 if id not in xref_dictionary:101 xref_dictionary[id] = os.path.basename(file)102 else:103 logging.warning('Non unique topic/section id %s in file %s. This is already found in %s'104 % (id, os.path.basename(file), os.path.basename(xref_dictionary[id])))105 66 106 67 def usage(arg): 107 print(' correct_references.py -d <ditafolder>')68 print('refsect2_to_refsect1.py -i <input_file> -o <output_file>') 108 69 sys.exit(arg) 109 70 110 71 def main(): 111 ditafolder = '' 72 input_file = '' 73 output_file = '' 112 74 try: 113 opts, args = getopt.getopt(sys.argv[1:],"h d:")75 opts, args = getopt.getopt(sys.argv[1:],"hi:o:") 114 76 except getopt.GetoptError as err: 115 77 print(err) … … 118 80 if opt == '-h': 119 81 usage(0) 120 elif opt in ("-d"): 121 ditafolder = arg 82 elif opt in ("-i"): 83 input_file = arg 84 elif opt in ("-o"): 85 output_file = arg 122 86 123 if not ditafolder:124 logging.error('No folderis provided. Exiting')87 if not input_file: 88 logging.error('No input file is provided. Exiting') 125 89 usage(2) 126 createXrefIdDictionary(ditafolder) 90 if not output_file: 91 logging.error('No output file is provided. Exiting') 92 usage(2) 127 93 128 vboxmanage_dita_files = glob.glob(ditafolder + "/man_V*dita") 129 for file in vboxmanage_dita_files: 130 file_handle = open(file, 'r', encoding="utf-8") 131 file_content = file_handle.readlines() 132 correctHrefTargets(file_content) 133 file_handle.close() 134 file_handle = open(file, 'w', encoding="utf-8") 135 file_handle.write("".join(file_content)) 136 file_handle.close() 94 file_handle = open(input_file, 'r', encoding="utf-8") 95 file_content = file_handle.readlines() 96 new_file_content = replaceRefsect2(file_content) 97 file_handle.close() 98 file_handle = open(output_file , 'w', encoding="utf-8") 99 file_handle.write("".join(new_file_content)) 100 file_handle.close() 137 101 138 102 if __name__ == "__main__":
Note:
See TracChangeset
for help on using the changeset viewer.