Also prevent unknown roles from causing formatting to error

This commit is contained in:
Kovid Goyal 2021-07-27 08:07:11 +05:30
parent 6c8eb4a19a
commit bc895eacc5
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C

View File

@ -204,7 +204,10 @@ def prettify(text: str) -> str:
def sub(m: Match) -> str: def sub(m: Match) -> str:
role, text = m.group(1, 2) role, text = m.group(1, 2)
return str(role_map[role](text)) try:
return str(role_map[role](text))
except KeyError:
return str(text)
text = re.sub(r':([a-z]+):`([^`]+)`', sub, text) text = re.sub(r':([a-z]+):`([^`]+)`', sub, text)
return text return text