From 463192242f37123d84a5682ea0ce87ecd801aba4 Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Wed, 30 Sep 2020 23:52:39 +0100 Subject: [PATCH] Fix test --- content.py | 32 ++++++++++++++++++++++++++++++-- tests.py | 13 ++++--------- 2 files changed, 34 insertions(+), 11 deletions(-) diff --git a/content.py b/content.py index 2fc75471..a34ee002 100644 --- a/content.py +++ b/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 '
' not in content: + return content + if '
' not in content: + return content + ctr = 1 + found = True + while found: + prefix = content.split('
', ctr)[0] + '
' + quotedStr = content.split('
', ctr)[1] + if '
' not in quotedStr: + found = False + else: + endStr = quotedStr.split('
')[1] + quotedStr = quotedStr.split('
')[0] + if '
' not in endStr: + found = False + if '
' in quotedStr: + quotedStr = quotedStr.replace('
', '') + content = prefix + quotedStr + '
' + 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 += '

' + lineStr + '

' else: lineStr = lineStr.replace('>> ', '>
') - lineStr = lineStr.replace('>', '
') + if lineStr.startswith('>'): + lineStr = lineStr.replace('>', '
', 1) + else: + lineStr = lineStr.replace('>', '
') newContent += '

' + lineStr + '

' - return newContent + return removeQuotesWithinQuotes(newContent) def htmlReplaceQuoteMarks(content: str) -> str: diff --git a/tests.py b/tests.py index 3d041a2f..9166866b 100644 --- a/tests.py +++ b/tests.py @@ -2125,7 +2125,7 @@ def testReplaceEmailQuote(): "

Some other text.

" 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

Some question?

" 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
>
> Text3
" + \ ">
> Text4
>
> " + \ "Text5
>
> Text6

Text7

" - expectedStr = "

" + \ - "@somenick" + \ - "

Text1.

" + \ - "Text2

Text3


Text4
" + \ - "
Text5

Text6

Text7

" + expectedStr = "

@somenick

Text1.

Text2

Text3
>
Text4

Text5

Text6

Text7

" resultStr = htmlReplaceEmailQuote(testStr) if resultStr != expectedStr: - print('Result: ' + resultStr) + print('Result: ' + str(resultStr)) print('Expect: ' + expectedStr) assert resultStr == expectedStr