From 8565f362e636d3a31754a46a850c73572b76873f Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Mon, 3 Aug 2020 18:03:30 +0100 Subject: [PATCH] Better handling of quotes --- content.py | 41 +++++++++++++++++++++-------------------- 1 file changed, 21 insertions(+), 20 deletions(-) diff --git a/content.py b/content.py index ef5069148..2d2bc7d88 100644 --- a/content.py +++ b/content.py @@ -19,28 +19,29 @@ def htmlReplaceQuoteMarks(content: str) -> str: "hello" becomes hello """ if '"' not in content: - return content + if '"' not in content: + return content - sections = content.split('"') - if len(sections) <= 2: - return content - - newContent = '' - openQuote = True - markup = False - for ch in content: - currChar = ch - if ch == '<': - markup = True - elif ch == '>': + newContent = content + if '"' in content: + sections = content.split('"') + if len(sections) > 1: + newContent = '' + openQuote = True markup = False - elif ch == '"' and not markup: - if openQuote: - currChar = '“' - else: - currChar = '”' - openQuote = not openQuote - newContent += currChar + for ch in content: + currChar = ch + if ch == '<': + markup = True + elif ch == '>': + markup = False + elif ch == '"' and not markup: + if openQuote: + currChar = '“' + else: + currChar = '”' + openQuote = not openQuote + newContent += currChar if '"' in newContent: openQuote = True