Convert html paragraphs

main
Bob Mottram 2021-03-23 10:52:10 +00:00
parent e422d29021
commit 02cbf4a2b9
2 changed files with 9 additions and 1 deletions

View File

@ -2275,8 +2275,15 @@ def testRemoveHtml():
assert(removeHtml(testStr) == testStr)
testStr = 'This string <a href="1234.567">has html</a>.'
assert(removeHtml(testStr) == 'This string has html.')
testStr = '<label>This string has.</label><label>Two labels.</label>'
assert(removeHtml(testStr) == 'This string has. Two labels.')
testStr = '<p>This string has.</p><p>Two paragraphs.</p>'
assert(removeHtml(testStr) == 'This string has. Two paragraphs.')
assert(removeHtml(testStr) == 'This string has.\n\nTwo paragraphs.')
testStr = 'This string has.<br>A new line.'
assert(removeHtml(testStr) == 'This string has.\nA new line.')
testStr = '<p>This string contains a url http://somesite.or.other</p>'
assert(removeHtml(testStr) == \
'This string contains a url http://somesite.or.other')
def testDangerousCSS():

View File

@ -255,6 +255,7 @@ def removeHtml(content: str) -> str:
removing = False
content = content.replace('<a href', ' <a href')
content = content.replace('<q>', '"').replace('</q>', '"')
content = content.replace('</p>', '\n\n').replace('<br>', '\n')
result = ''
for ch in content:
if ch == '<':