From 323cb4a91b4a37e219d80e8ee2e72a81ee9e2442 Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Sun, 2 Aug 2020 20:16:22 +0100 Subject: [PATCH] Replace quotes --- content.py | 17 +++++++++++++++++ tests.py | 4 ++-- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/content.py b/content.py index 69c5f0905..ef5069148 100644 --- a/content.py +++ b/content.py @@ -41,6 +41,23 @@ def htmlReplaceQuoteMarks(content: str) -> str: currChar = '”' openQuote = not openQuote newContent += currChar + + if '"' in newContent: + openQuote = True + content = newContent + newContent = '' + ctr = 0 + sections = content.split('"') + noOfSections = len(sections) + for s in sections: + newContent += s + if ctr < noOfSections - 1: + if openQuote: + newContent += '“' + else: + newContent += '”' + openQuote = not openQuote + ctr += 1 return newContent diff --git a/tests.py b/tests.py index 68dbaaad6..2f85cd218 100644 --- a/tests.py +++ b/tests.py @@ -1938,9 +1938,9 @@ def runHtmlReplaceQuoteMarks(): result = htmlReplaceQuoteMarks(testStr) assert result == '“hello”' - testStr = '"hello" test html' + testStr = '"hello" "test" html' result = htmlReplaceQuoteMarks(testStr) - assert result == '“hello” test html' + assert result == '“hello” “test” html' def runAllTests():