main
Bob Mottram 2020-09-30 23:52:39 +01:00
parent a9a3a8321d
commit 463192242f
2 changed files with 34 additions and 11 deletions

View File

@ -13,6 +13,31 @@ from utils import loadJson
from utils import fileLastModified
from utils import getLinkPrefixes
def removeQuotesWithinQuotes(content: str) -> str:
"""Removes any blockquote inside blockquote
"""
if '<blockquote>' not in content:
return content
if '</blockquote>' not in content:
return content
ctr = 1
found = True
while found:
prefix = content.split('<blockquote>', ctr)[0] + '<blockquote>'
quotedStr = content.split('<blockquote>', ctr)[1]
if '</blockquote>' not in quotedStr:
found = False
else:
endStr = quotedStr.split('</blockquote>')[1]
quotedStr = quotedStr.split('</blockquote>')[0]
if '<blockquote>' not in endStr:
found = False
if '<blockquote>' in quotedStr:
quotedStr = quotedStr.replace('<blockquote>', '')
content = prefix + quotedStr + '</blockquote>' + endStr
ctr += 1
return content
def htmlReplaceEmailQuote(content: str) -> str:
"""Replaces an email style quote "> Some quote" with html blockquote
@ -44,9 +69,12 @@ def htmlReplaceEmailQuote(content: str) -> str:
newContent += '<p>' + lineStr + '</p>'
else:
lineStr = lineStr.replace('>&gt; ', '><blockquote>')
lineStr = lineStr.replace('&gt;', '<br>')
if lineStr.startswith('&gt;'):
lineStr = lineStr.replace('&gt;', '<blockquote>', 1)
else:
lineStr = lineStr.replace('&gt;', '<br>')
newContent += '<p>' + lineStr + '</blockquote></p>'
return newContent
return removeQuotesWithinQuotes(newContent)
def htmlReplaceQuoteMarks(content: str) -> str:

View File

@ -2125,7 +2125,7 @@ def testReplaceEmailQuote():
"<p>Some other text.</p>"
resultStr = htmlReplaceEmailQuote(testStr)
if resultStr != expectedStr:
print('Result: ' + resultStr)
print('Result: ' + str(resultStr))
print('Expect: ' + expectedStr)
assert resultStr == expectedStr
@ -2135,7 +2135,7 @@ def testReplaceEmailQuote():
"second line</blockquote></p><p>Some question?</p>"
resultStr = htmlReplaceEmailQuote(testStr)
if resultStr != expectedStr:
print('Result: ' + resultStr)
print('Result: ' + str(resultStr))
print('Expect: ' + expectedStr)
assert resultStr == expectedStr
@ -2146,15 +2146,10 @@ def testReplaceEmailQuote():
"&gt; Text2<br />&gt; <br />&gt; Text3<br />" + \
"&gt;<br />&gt; Text4<br />&gt; <br />&gt; " + \
"Text5<br />&gt; <br />&gt; Text6</p><p>Text7</p>"
expectedStr = "<p><span class=\"h-card\">" + \
"<a href=\"https://somedomain/@somenick\" " + \
"class=\"u-url mention\">@<span>somenick</span></a>" + \
"</span> </p><p><blockquote> Text1.<br /><br />" + \
"Text2<br /><br />Text3<br /><br><br />Text4<br />" + \
"<br />Text5<br /><br />Text6</blockquote></p><p>Text7</p>"
expectedStr = "<p><span class=\"h-card\"><a href=\"https://somedomain/@somenick\" class=\"u-url mention\">@<span>somenick</span></a></span> </p><p><blockquote> Text1.<br /><br />Text2<br /><br />Text3<br />&gt;<br />Text4<br /><br />Text5<br /><br />Text6</blockquote></p><p>Text7</p>"
resultStr = htmlReplaceEmailQuote(testStr)
if resultStr != expectedStr:
print('Result: ' + resultStr)
print('Result: ' + str(resultStr))
print('Expect: ' + expectedStr)
assert resultStr == expectedStr