forked from indymedia/epicyon
Use html formatting for quotes
parent
73b8f67f61
commit
3c86717fc6
30
content.py
30
content.py
|
@ -14,6 +14,33 @@ from utils import fileLastModified
|
||||||
from utils import getLinkPrefixes
|
from utils import getLinkPrefixes
|
||||||
|
|
||||||
|
|
||||||
|
def htmlReplaceQuoteMarks(content: str) -> str:
|
||||||
|
"""Replaces quotes with html formatting
|
||||||
|
"hello" becomes <q>hello</q>
|
||||||
|
"""
|
||||||
|
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 += '<q>'
|
||||||
|
else:
|
||||||
|
newContent += '</q>'
|
||||||
|
openQuote = not openQuote
|
||||||
|
ctr += 1
|
||||||
|
return newContent
|
||||||
|
|
||||||
|
|
||||||
def dangerousMarkup(content: str) -> bool:
|
def dangerousMarkup(content: str) -> bool:
|
||||||
"""Returns true if the given content contains dangerous html markup
|
"""Returns true if the given content contains dangerous html markup
|
||||||
"""
|
"""
|
||||||
|
@ -433,6 +460,7 @@ def removeHtml(content: str) -> str:
|
||||||
if '<' not in content:
|
if '<' not in content:
|
||||||
return content
|
return content
|
||||||
removing = False
|
removing = False
|
||||||
|
content = content.replace('<q>', '"').replace('</q>', '"')
|
||||||
result = ''
|
result = ''
|
||||||
for ch in content:
|
for ch in content:
|
||||||
if ch == '<':
|
if ch == '<':
|
||||||
|
@ -608,7 +636,7 @@ def addHtmlTags(baseDir: str, httpPrefix: str,
|
||||||
if longWordsList:
|
if longWordsList:
|
||||||
content = removeLongWords(content, maxWordLength, longWordsList)
|
content = removeLongWords(content, maxWordLength, longWordsList)
|
||||||
content = content.replace(' --linebreak-- ', '</p><p>')
|
content = content.replace(' --linebreak-- ', '</p><p>')
|
||||||
return '<p>' + content + '</p>'
|
return '<p>' + htmlReplaceQuoteMarks(content) + '</p>'
|
||||||
|
|
||||||
|
|
||||||
def getMentionsFromHtml(htmlText: str,
|
def getMentionsFromHtml(htmlText: str,
|
||||||
|
|
Binary file not shown.
17
tests.py
17
tests.py
|
@ -64,6 +64,7 @@ from media import getAttachmentMediaType
|
||||||
from delete import sendDeleteViaServer
|
from delete import sendDeleteViaServer
|
||||||
from inbox import validInbox
|
from inbox import validInbox
|
||||||
from inbox import validInboxFilenames
|
from inbox import validInboxFilenames
|
||||||
|
from content import htmlReplaceQuoteMarks
|
||||||
from content import dangerousMarkup
|
from content import dangerousMarkup
|
||||||
from content import removeHtml
|
from content import removeHtml
|
||||||
from content import addWebLinks
|
from content import addWebLinks
|
||||||
|
@ -1923,8 +1924,24 @@ def testDangerousMarkup():
|
||||||
assert(not dangerousMarkup(content))
|
assert(not dangerousMarkup(content))
|
||||||
|
|
||||||
|
|
||||||
|
def runHtmlReplaceQuoteMarks():
|
||||||
|
print('htmlReplaceQuoteMarks')
|
||||||
|
testStr = 'The "cat" "sat" on the mat'
|
||||||
|
result = htmlReplaceQuoteMarks(testStr)
|
||||||
|
assert result == 'The <q>cat</q> <q>sat</q> on 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 == '<q>hello</q>'
|
||||||
|
|
||||||
|
|
||||||
def runAllTests():
|
def runAllTests():
|
||||||
print('Running tests...')
|
print('Running tests...')
|
||||||
|
runHtmlReplaceQuoteMarks()
|
||||||
testDangerousMarkup()
|
testDangerousMarkup()
|
||||||
testRemoveHtml()
|
testRemoveHtml()
|
||||||
testSiteIsActive()
|
testSiteIsActive()
|
||||||
|
|
Loading…
Reference in New Issue