Fix changelog parsing when encountering inline code

Fixes: https://github.com/brave/brave-browser/issues/8133
This commit is contained in:
Matt Bacchi
2020-02-11 15:14:45 -07:00
parent 234388745e
commit 52adaaa51b
+20 -5
View File
@@ -57,11 +57,26 @@ def reconstruct_brave_changelog_list(li):
changes = []
for item in li['children']:
for item2 in item['children']:
changes.append("{} {}[{}]({}){}".format(' -', item2['children'][0]['content'],
item2['children'][1]['children'][0]['content'],
item2['children'][1]['target'],
item2['children'][2]['content']))
# For special markdown characters such as *EMPHASIS* or `inline code
# blocks`, mistletoe's AST provides us with a nested list. We need
# to traverse the list elements and append them to a single string.
# During this process we also remove the special characters.
appended_entry = str()
for item2 in item['children'][0]['children']:
if 'RawText' in item2['type']:
appended_entry = appended_entry + '{}'.format(item2['content'])
elif 'Link' in item2['type']:
appended_entry = appended_entry + '[{}]({})'.format(item2['children'][0]['content'], item2['target'])
elif 'InlineCode' in item2['type']:
appended_entry = appended_entry + '{}'.format(item2['children'][0]['content'])
else:
# Try to catch all other markdown types in this general case
#
# Mistletoe types defined here:
# https://github.com/miyuchina/mistletoe/blob/master/mistletoe/base_renderer.py#L47-L71
appended_entry = appended_entry + '{}'.format(item2['children'][0]['content'])
changes.append(" {} {}".format(' -', appended_entry))
return changes