MCPcopy Create free account
hub / github.com/emscripten-core/emscripten / FixupConvertedRstFiles

Function FixupConvertedRstFiles

site/source/get_wiki.py:138–193  ·  view source on GitHub ↗

Add template to specified page object (wikitools).

()

Source from the content-addressed store, hash-verified

136
137
138def FixupConvertedRstFiles():
139 """Add template to specified page object (wikitools)."""
140
141 def fixInternalWikiLinks(aOldText):
142 """Fixes wiki links in [[linkname]] format by changing this to a document link in current directory."""
143 def fixwikilinks(matchobj):
144 # print 'matcobj0: %s' % matchobj.group(0)
145 # print 'matcobj1: %s' % matchobj.group(1)
146 linktext = matchobj.group(1)
147 linktext = linktext.replace(' ', '-')
148 # linktext = ':doc:`%s`' % linktext
149 # use reference for linking as allows pages to be moved around
150 linktext = ':ref:`%s`' % linktext
151 # print 'linkdoc: %s' % linktext
152 logfile.write('linkdoc: %s \n' % linktext)
153 return linktext
154 # print 'fixing wiki links'
155 return re.sub(r'\[\[(.+?)\]\]', fixwikilinks, aOldText)
156
157 def fixWikiCodeMarkupToCodeLinks(aOldText):
158 """Links "known" code objects if they are found in wiki markup."""
159 def fixcodemarkuplinks(matchobj):
160 # print 'Inline code: %s' % matchobj.group(0)
161 # print 'matcobj1: %s' % matchobj.group(1)
162 temp_set_of_codemarkup.add(matchobj.group(0))
163 linktext = matchobj.group(1)
164 if linktext in mapped_wiki_inline_code:
165 logfile.write('Replace: %s \n' % mapped_wiki_inline_code[linktext])
166 return mapped_wiki_inline_code[linktext]
167
168 return matchobj.group(0) # linktext
169 # print 'fixing up code markup to code reference'
170 return re.sub(r'``(.+?)``', fixcodemarkuplinks, aOldText)
171
172 for file in os.listdir(output_dir):
173 if file.endswith(".rst"):
174 input_file = output_dir + file
175 # print input_file
176 textinfile = ''
177 with open(input_file, encoding='utf-8') as infile:
178 for line in infile:
179 textinfile += line
180
181 # print textinfile
182 # fix up broken wiki-page links in files
183 textinfile = fixInternalWikiLinks(textinfile)
184
185 # convert codemarkup to links if possible
186 textinfile = fixWikiCodeMarkupToCodeLinks(textinfile)
187
188 with open(input_file, 'w', encoding='utf-8') as outfile:
189 outfile.write(textinfile)
190
191 logfile.write('\n\nCODE MARKUP THAT WONT BE LINKED (add entry to mapped_wiki_inline_code if one of these need to be linked. The tool get-api-items.py can be used to generate the list of the documented API items. \n')
192 for item in temp_set_of_codemarkup:
193 logfile.write('%s\n' % item)
194
195

Callers 1

mainFunction · 0.85

Calls 4

fixInternalWikiLinksFunction · 0.85
openFunction · 0.50
writeMethod · 0.45

Tested by

no test coverage detected