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 = ''
openQuote = True
noOfSections = len(sections)
ctr = 0
for s in sections:
newContent += s
if ctr < noOfSections - 1:
markup = False
for ch in content:
currChar = ch
if ch == '<':
markup = True
elif ch == '>':
markup = False
elif ch == '"' and not markup:
if openQuote:
newContent += '<q>'
currChar = '<q>'
else:
newContent += '</q>'
currChar = '</q>'
openQuote = not openQuote
ctr += 1
newContent += currChar
return newContent

View File

@ -1938,6 +1938,10 @@ def runHtmlReplaceQuoteMarks():
result = htmlReplaceQuoteMarks(testStr)
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():
print('Running tests...')