comparison src/plugins/plugin_misc_text_syntaxes.py @ 841:831f208b4ea3

plugin text_syntaxes: html2text was breaking the long URLs
author souliane <souliane@mailoo.org>
date Thu, 13 Feb 2014 12:29:14 +0100
parents 2cc0201b4613
children 4cc55e05266d
comparison
equal deleted inserted replaced
840:58b4568ed4f2 841:831f208b4ea3
102 self.addSyntax(self.SYNTAX_XHTML, lambda xhtml: defer.succeed(xhtml), lambda xhtml: defer.succeed(xhtml), 102 self.addSyntax(self.SYNTAX_XHTML, lambda xhtml: defer.succeed(xhtml), lambda xhtml: defer.succeed(xhtml),
103 TextSyntaxes.OPT_NO_THREAD) 103 TextSyntaxes.OPT_NO_THREAD)
104 self.addSyntax(self.SYNTAX_TEXT, lambda text: escape(text), lambda xhtml: self._removeMarkups(xhtml), [TextSyntaxes.OPT_HIDDEN]) 104 self.addSyntax(self.SYNTAX_TEXT, lambda text: escape(text), lambda xhtml: self._removeMarkups(xhtml), [TextSyntaxes.OPT_HIDDEN])
105 try: 105 try:
106 import markdown, html2text 106 import markdown, html2text
107 self.addSyntax(self.SYNTAX_MARKDOWN, markdown.markdown, html2text.html2text, [TextSyntaxes.OPT_DEFAULT]) 107
108 def _html2text(html, baseurl=''):
109 h = html2text.HTML2Text(baseurl=baseurl)
110 h.body_width = 0 # do not truncate the lines, it breaks the long URLs
111 return h.handle(html)
112 self.addSyntax(self.SYNTAX_MARKDOWN, markdown.markdown, _html2text, [TextSyntaxes.OPT_DEFAULT])
108 except ImportError: 113 except ImportError:
109 warning("markdown or html2text not found, can't use Markdown syntax") 114 warning("markdown or html2text not found, can't use Markdown syntax")
110 host.bridge.addMethod("syntaxConvert", ".plugin", in_sign='sssbs', out_sign='s', 115 host.bridge.addMethod("syntaxConvert", ".plugin", in_sign='sssbs', out_sign='s',
111 async=True, method=self.convert) 116 async=True, method=self.convert)
112 117