From 97ef88c9483cb219c09b8c923719495cf734691a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ant=C3=B3nio=20In=C3=A1cio?= Date: Fri, 15 Sep 2017 16:55:58 +0100 Subject: [PATCH] Fixed undesired line breaks and Markdown syntax for Links. The mentioned line breaks where corrupting URLs, after some default line length, so text was being split into lines automatically (and therefore corrupting URLs). Links of type [http://someurl.com](http://someurl.com) can be expressed as , so we have to tell the markdown processor to handle it like such. --- geeknote/editor.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/geeknote/editor.py b/geeknote/editor.py index fcdd7b4..e551180 100644 --- a/geeknote/editor.py +++ b/geeknote/editor.py @@ -157,7 +157,12 @@ def ENMLtoText(contentENML, format='default', imageOptions={'saveImages': False} # content = html2text.html2text(soup.prettify()) # content = html2text.html2text(str(soup)) # content = html2text.html2text(unicode(soup)) - content = html2text.html2text(str(soup).decode('utf-8'), '') +# content = h.html2text(str(soup).decode('utf-8'), '') + + # Prevent undesired line breaks + h = html2text.HTML2Text() + h.body_width = 0 + content = h.handle(str(soup).decode('utf-8')) content = re.sub(r' *\n', os.linesep, content) content = content.replace(unichr(160), " ") @@ -239,6 +244,11 @@ def textToENML(content, raise_ex=False, format='markdown', rawmd=False): storage = Storage() extras = storage.getUserprop('markdown2_extras') + # markdown for links of type [http://someurl.com](http://someurl.com) + # can be expressed as , so we have to tell the + # markdown processor to handle it like such. + content = re.sub(r'(?:<)(http[^>]+)>', r'[\1](\1)', content) + if not rawmd: content = Editor.HTMLEscapeTag(content)