forked from indymedia/epicyon
Fix test
parent
a9a3a8321d
commit
463192242f
30
content.py
30
content.py
|
@ -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('>> ', '><blockquote>')
|
||||
if lineStr.startswith('>'):
|
||||
lineStr = lineStr.replace('>', '<blockquote>', 1)
|
||||
else:
|
||||
lineStr = lineStr.replace('>', '<br>')
|
||||
newContent += '<p>' + lineStr + '</blockquote></p>'
|
||||
return newContent
|
||||
return removeQuotesWithinQuotes(newContent)
|
||||
|
||||
|
||||
def htmlReplaceQuoteMarks(content: str) -> str:
|
||||
|
|
13
tests.py
13
tests.py
|
@ -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():
|
|||
"> Text2<br />> <br />> Text3<br />" + \
|
||||
"><br />> Text4<br />> <br />> " + \
|
||||
"Text5<br />> <br />> 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 />><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
|
||||
|
||||
|
|
Loading…
Reference in New Issue