Avoid adding quites within markup

main
Bob Mottram 2020-08-02 18:17:51 +01:00
parent 3c86717fc6
commit 5efc685220
2 changed files with 15 additions and 8 deletions

View File

@ -27,17 +27,20 @@ def htmlReplaceQuoteMarks(content: str) -> str:
newContent = '' newContent = ''
openQuote = True openQuote = True
noOfSections = len(sections) markup = False
ctr = 0 for ch in content:
for s in sections: currChar = ch
newContent += s if ch == '<':
if ctr < noOfSections - 1: markup = True
elif ch == '>':
markup = False
elif ch == '"' and not markup:
if openQuote: if openQuote:
newContent += '<q>' currChar = '<q>'
else: else:
newContent += '</q>' currChar = '</q>'
openQuote = not openQuote openQuote = not openQuote
ctr += 1 newContent += currChar
return newContent return newContent

View File

@ -1938,6 +1938,10 @@ def runHtmlReplaceQuoteMarks():
result = htmlReplaceQuoteMarks(testStr) result = htmlReplaceQuoteMarks(testStr)
assert result == '<q>hello</q>' assert result == '<q>hello</q>'
testStr = '"hello" <a href="somesite.html">test html</a>'
result = htmlReplaceQuoteMarks(testStr)
assert result == '<q>hello</q> <a href="somesite.html">test html</a>'
def runAllTests(): def runAllTests():
print('Running tests...') print('Running tests...')