replace convert links fn with fns in QRG build script

This commit is contained in:
Steve Baskauf 2021-08-05 21:30:03 -05:00
parent 2e9df5bfc3
commit bb3d93d4c9
1 changed files with 24 additions and 5 deletions

View File

@ -68,6 +68,25 @@ def createLinks(text):
result = re.sub(pattern, repl, text)
return result
# 2021-08-05 Replace the createLinks() function with functions copied from the QRG build script written by S. Van Hoey
def convert_code(text_with_backticks):
"""Takes all back-quoted sections in a text field and converts it to
the html tagged version of code blocks <code>...</code>
"""
return re.sub(r'`([^`]*)`', r'<code>\1</code>', text_with_backticks)
def convert_link(text_with_urls):
"""Takes all links in a text field and converts it to the html tagged
version of the link
"""
def _handle_matched(inputstring):
"""quick hack version of url handling on the current prime versions data"""
url = inputstring.group()
return "<a href=\"{}\">{}</a>".format(url, url)
regx = "(http[s]?://[\w\d:#@%/;$()~_?\+-;=\\\.&]*)(?<![\)\.])"
return re.sub(regx, _handle_matched, text_with_urls)
# ---------------
# Retrieve term list metadata from GitHub
# ---------------
@ -318,22 +337,22 @@ if True:
#if row['notes'] != '':
text += '\t\t<tr>\n'
text += '\t\t\t<td>Notes</td>\n'
text += '\t\t\t<td>' + createLinks(row['dcterms_description']) + '</td>\n'
#text += '\t\t\t<td>' + createLinks(row['notes']) + '</td>\n'
text += '\t\t\t<td>' + convert_link(convert_code(row['dcterms_description'])) + '</td>\n'
#text += '\t\t\t<td>' + convert_link(convert_code(row['notes'])) + '</td>\n'
text += '\t\t</tr>\n'
if row['examples'] != '':
#if row['usage'] != '':
text += '\t\t<tr>\n'
text += '\t\t\t<td>Examples</td>\n'
text += '\t\t\t<td>' + createLinks(row['examples']) + '</td>\n'
#text += '\t\t\t<td>' + createLinks(row['usage']) + '</td>\n'
text += '\t\t\t<td>' + convert_link(convert_code(row['examples'])) + '</td>\n'
#text += '\t\t\t<td>' + convert_link(convert_code(row['usage'])) + '</td>\n'
text += '\t\t</tr>\n'
if row['tdwgutility_abcdEquivalence'] != '':
text += '\t\t<tr>\n'
text += '\t\t\t<td>ABCD equivalence</td>\n'
text += '\t\t\t<td>' + createLinks(row['tdwgutility_abcdEquivalence']) + '</td>\n'
text += '\t\t\t<td>' + convert_link(convert_code(row['tdwgutility_abcdEquivalence'])) + '</td>\n'
text += '\t\t</tr>\n'
if vocab_type == 2 or vocab_type ==3: # controlled vocabulary