From 377b6a9be313b6a51808ad20a6cbaee135964396 Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Thu, 25 Feb 2021 17:57:15 +0000 Subject: [PATCH] Fix markdown emphasis --- defaultwelcome/final_en.md | 1 - webapp_utils.py | 53 ++++++++++++++++++++++++++------------ 2 files changed, 37 insertions(+), 17 deletions(-) diff --git a/defaultwelcome/final_en.md b/defaultwelcome/final_en.md index fdfaf801b..ef9eb2601 100644 --- a/defaultwelcome/final_en.md +++ b/defaultwelcome/final_en.md @@ -2,7 +2,6 @@ You are now ready to begin using Epicyon. This is a moderated social space, so please make sure to abide by our [terms of service](/terms), and have fun. ### Hints - Use the **magnifier** icon 🔍 to search for fediverse handles and follow people. Selecting the **banner at the top** of the screen switches between timeline view and your profile. diff --git a/webapp_utils.py b/webapp_utils.py index 4d7c25f8b..5c3983bc2 100644 --- a/webapp_utils.py +++ b/webapp_utils.py @@ -24,24 +24,45 @@ from content import replaceEmojiFromTags def _markdownEmphasisHtml(markdown: str) -> str: """Add italics and bold html markup to the given markdown """ - punctuation = ('.', ';', ':') - noPunctuation = markdown - for ch in punctuation: - noPunctuation = noPunctuation.replace(ch, ' ') - wordList = noPunctuation.split(' ') - replacements = {} - for word in wordList: - if word.startswith('**') and word.endswith('**'): - replacements[word] = \ - '' + word.replace('*', '') + '' - elif word.startswith('*') and word.endswith('*'): - replacements[word] = \ - '' + word.replace('*', '') + '' - elif word.startswith('_') and word.endswith('_'): - replacements[word] = \ - '' + replacements = { + ' **': ' ', + '** ': ' ', + '**.': '.', + '**:': ':', + '**;': ';', + '**,': ',', + '**\n': '\n', + ' *': ' ', + '* ': ' ', + '*.': '.', + '*:': ':', + '*;': ';', + '*,': ',', + '*\n': '\n', + ' _': ' ', + '_.': '.', + '_:': ':', + '_;': ';', + '_,': ',', + '_\n': '\n' + } for md, html in replacements.items(): markdown = markdown.replace(md, html) + + if markdown.startswith('**'): + markdown = markdown[2:] + '' + elif markdown.startswith('*'): + markdown = markdown[1:] + '' + elif markdown.startswith('_'): + markdown = markdown[1:] + '' return markdown