diff --git a/content.py b/content.py
index bc3c9af4..bf82ce03 100644
--- a/content.py
+++ b/content.py
@@ -14,6 +14,33 @@ from utils import fileLastModified
from utils import getLinkPrefixes
+def htmlReplaceQuoteMarks(content: str) -> str:
+ """Replaces quotes with html formatting
+ "hello" becomes hello
+ """
+ if '"' not in content:
+ return content
+
+ sections = content.split('"')
+ if len(sections) <= 2:
+ return content
+
+ newContent = ''
+ openQuote = True
+ noOfSections = len(sections)
+ ctr = 0
+ for s in sections:
+ newContent += s
+ if ctr < noOfSections - 1:
+ if openQuote:
+ newContent += ''
+ else:
+ newContent += '
'
+ openQuote = not openQuote
+ ctr += 1
+ return newContent
+
+
def dangerousMarkup(content: str) -> bool:
"""Returns true if the given content contains dangerous html markup
"""
@@ -433,6 +460,7 @@ def removeHtml(content: str) -> str:
if '<' not in content:
return content
removing = False
+ content = content.replace('', '"').replace('
', '"')
result = ''
for ch in content:
if ch == '<':
@@ -608,7 +636,7 @@ def addHtmlTags(baseDir: str, httpPrefix: str,
if longWordsList:
content = removeLongWords(content, maxWordLength, longWordsList)
content = content.replace(' --linebreak-- ', '
') - return '
' + content + '
' + return '' + htmlReplaceQuoteMarks(content) + '
' def getMentionsFromHtml(htmlText: str, diff --git a/fonts/solidaric.woff2 b/fonts/solidaric.woff2 index 167ef223..0fda1bee 100644 Binary files a/fonts/solidaric.woff2 and b/fonts/solidaric.woff2 differ diff --git a/tests.py b/tests.py index 1c43a0f3..e1038c34 100644 --- a/tests.py +++ b/tests.py @@ -64,6 +64,7 @@ from media import getAttachmentMediaType from delete import sendDeleteViaServer from inbox import validInbox from inbox import validInboxFilenames +from content import htmlReplaceQuoteMarks from content import dangerousMarkup from content import removeHtml from content import addWebLinks @@ -1923,8 +1924,24 @@ def testDangerousMarkup(): assert(not dangerousMarkup(content)) +def runHtmlReplaceQuoteMarks(): + print('htmlReplaceQuoteMarks') + testStr = 'The "cat" "sat" on the mat' + result = htmlReplaceQuoteMarks(testStr) + assert result == 'Thecat
saton the mat' + + testStr = 'The cat sat on the mat' + result = htmlReplaceQuoteMarks(testStr) + assert result == 'The cat sat on the mat' + + testStr = '"hello"' + result = htmlReplaceQuoteMarks(testStr) + assert result == '
hello' + + def runAllTests(): print('Running tests...') + runHtmlReplaceQuoteMarks() testDangerousMarkup() testRemoveHtml() testSiteIsActive()