plugin text_syntaxes: html2text was breaking the long URLs
This commit is contained in:
parent
d5611ae016
commit
d5fb045f5b
2 changed files with 15 additions and 1 deletions
|
|
@ -104,7 +104,12 @@ class TextSyntaxes(object):
|
||||||
self.addSyntax(self.SYNTAX_TEXT, lambda text: escape(text), lambda xhtml: self._removeMarkups(xhtml), [TextSyntaxes.OPT_HIDDEN])
|
self.addSyntax(self.SYNTAX_TEXT, lambda text: escape(text), lambda xhtml: self._removeMarkups(xhtml), [TextSyntaxes.OPT_HIDDEN])
|
||||||
try:
|
try:
|
||||||
import markdown, html2text
|
import markdown, html2text
|
||||||
self.addSyntax(self.SYNTAX_MARKDOWN, markdown.markdown, html2text.html2text, [TextSyntaxes.OPT_DEFAULT])
|
|
||||||
|
def _html2text(html, baseurl=''):
|
||||||
|
h = html2text.HTML2Text(baseurl=baseurl)
|
||||||
|
h.body_width = 0 # do not truncate the lines, it breaks the long URLs
|
||||||
|
return h.handle(html)
|
||||||
|
self.addSyntax(self.SYNTAX_MARKDOWN, markdown.markdown, _html2text, [TextSyntaxes.OPT_DEFAULT])
|
||||||
except ImportError:
|
except ImportError:
|
||||||
warning("markdown or html2text not found, can't use Markdown syntax")
|
warning("markdown or html2text not found, can't use Markdown syntax")
|
||||||
host.bridge.addMethod("syntaxConvert", ".plugin", in_sign='sssbs', out_sign='s',
|
host.bridge.addMethod("syntaxConvert", ".plugin", in_sign='sssbs', out_sign='s',
|
||||||
|
|
|
||||||
|
|
@ -86,6 +86,15 @@ class SanitisationTest(helpers.SatTestCase):
|
||||||
d.addCallback(self.assertEqualXML, expected)
|
d.addCallback(self.assertEqualXML, expected)
|
||||||
return d
|
return d
|
||||||
|
|
||||||
|
def test_html2text(self):
|
||||||
|
"""Check that html2text is not inserting \n in the middle of that link.
|
||||||
|
By default lines are truncated after the 79th characters."""
|
||||||
|
source = "<img src=\"http://sat.goffi.org/static/images/screenshots/libervia/libervia_discussions.png\" alt=\"sat\"/>"
|
||||||
|
expected = ""
|
||||||
|
d = self.text_syntaxes.convert(source, self.text_syntaxes.SYNTAX_XHTML, self.text_syntaxes.SYNTAX_MARKDOWN)
|
||||||
|
d.addCallback(self.assertEqual, expected)
|
||||||
|
return d
|
||||||
|
|
||||||
def test_removeXHTMLMarkups(self):
|
def test_removeXHTMLMarkups(self):
|
||||||
expected = """ a link another link a paragraph secret EVIL! of EVIL! Password: annoying EVIL!spam spam SPAM! """
|
expected = """ a link another link a paragraph secret EVIL! of EVIL! Password: annoying EVIL!spam spam SPAM! """
|
||||||
result = self.text_syntaxes._removeMarkups(self.EVIL_HTML1)
|
result = self.text_syntaxes._removeMarkups(self.EVIL_HTML1)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue