From c38851a6cd6f0d7da19fc48d4c9ac98596f32600 Mon Sep 17 00:00:00 2001 From: Steffen Prince Date: Wed, 28 Oct 2015 19:39:57 -0700 Subject: [PATCH 1/3] Update to misaka 2.0 Fixes #208 --- isso/utils/html.py | 2 +- setup.py | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/isso/utils/html.py b/isso/utils/html.py index 1f5f8cd..8ed5738 100644 --- a/isso/utils/html.py +++ b/isso/utils/html.py @@ -72,7 +72,7 @@ def Markdown(extensions=("strikethrough", "superscript", "autolink")): md = misaka.Markdown(Unofficial(), extensions=flags) def inner(text): - rv = md.render(text).rstrip("\n") + rv = md(text).rstrip("\n") if rv.startswith("

") or rv.endswith("

"): return rv return "

" + rv + "

" diff --git a/setup.py b/setup.py index ef866fe..5b90acb 100644 --- a/setup.py +++ b/setup.py @@ -5,8 +5,8 @@ import sys from setuptools import setup, find_packages -requires = ['html5lib==0.9999999', 'itsdangerous', 'Jinja2', - 'misaka>=1.0,<2.0', 'werkzeug>=0.9'] +requires = ['itsdangerous', 'Jinja2', 'misaka>=2.0,<3.0', 'html5lib<0.9999999', + 'werkzeug>=0.9'] if sys.version_info < (2, 7): raise SystemExit("Python 2 versions < 2.7 are not supported.") From eef7ea261dffa290d2d985d437e208b8cad8b557 Mon Sep 17 00:00:00 2001 From: Steffen Prince Date: Wed, 28 Oct 2015 20:00:04 -0700 Subject: [PATCH 2/3] Add `cffi` to `setup_requires` --- setup.py | 1 + 1 file changed, 1 insertion(+) diff --git a/setup.py b/setup.py index 5b90acb..74b1c54 100644 --- a/setup.py +++ b/setup.py @@ -39,6 +39,7 @@ setup( extras_require={ ':python_version=="2.7"': ['ipaddr>=2.1', 'configparser'] }, + setup_requires=["cffi>=1.3.0"], entry_points={ 'console_scripts': ['isso = isso:main'], From 7cdb47d8751b106414f85ec7409ece35f81c5d10 Mon Sep 17 00:00:00 2001 From: Steffen Prince Date: Thu, 29 Oct 2015 13:24:33 -0700 Subject: [PATCH 3/3] Update renderer to match Misaka 2.0 API --- CHANGES.rst | 1 + CONTRIBUTORS.txt | 3 +++ isso/tests/test_html.py | 2 +- isso/utils/html.py | 16 +++++++--------- 4 files changed, 12 insertions(+), 10 deletions(-) diff --git a/CHANGES.rst b/CHANGES.rst index 5005f64..bb055b7 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -19,6 +19,7 @@ Changelog for Isso - Add optionnal gravatar support - Add nofollow noopener on links inside comments - Add Dockerfile +- Upgraded to Misaka 2 - Some tests/travis/documentation improvements and fixes + pep8 - Improvement on german translation diff --git a/CONTRIBUTORS.txt b/CONTRIBUTORS.txt index 10537ff..4581ef3 100644 --- a/CONTRIBUTORS.txt +++ b/CONTRIBUTORS.txt @@ -89,5 +89,8 @@ In chronological order: * @benjhess * Optionnal gravatar support +* Steffen Prince @sprin + * Upgrade to Misaka 2 + * [Your name or handle] <[email or website]> * [Brief summary of your changes] diff --git a/isso/tests/test_html.py b/isso/tests/test_html.py index 42baa82..2b3b15c 100644 --- a/isso/tests/test_html.py +++ b/isso/tests/test_html.py @@ -29,7 +29,7 @@ class TestHTML(unittest.TestCase): self.assertEqual(convert(input), expected) def test_github_flavoured_markdown(self): - convert = html.Markdown(extensions=("fenced_code", )) + convert = html.Markdown(extensions=("fenced-code", )) # without lang _in = textwrap.dedent("""\ diff --git a/isso/utils/html.py b/isso/utils/html.py index 8ed5738..4acfcc0 100644 --- a/isso/utils/html.py +++ b/isso/utils/html.py @@ -2,7 +2,6 @@ from __future__ import unicode_literals -import operator import pkg_resources from distutils.version import LooseVersion as Version @@ -10,8 +9,6 @@ from distutils.version import LooseVersion as Version HTML5LIB_VERSION = Version(pkg_resources.get_distribution("html5lib").version) HTML5LIB_SIMPLETREE = Version("0.95") -from isso.compat import reduce - import html5lib from html5lib.sanitizer import HTMLSanitizer from html5lib.serializer import HTMLSerializer @@ -23,7 +20,8 @@ def Sanitizer(elements, attributes): class Inner(HTMLSanitizer): - # attributes found in Sundown's HTML serializer [1] except for tag, + # attributes found in Sundown's HTML serializer [1] + # except for tag, # because images are not generated anyways. # # [1] https://github.com/vmg/sundown/blob/master/html/html.c @@ -65,11 +63,11 @@ def sanitize(tokenizer, document): return serializer.render(stream) -def Markdown(extensions=("strikethrough", "superscript", "autolink")): +def Markdown(extensions=("strikethrough", "superscript", "autolink", + "fenced-code")): - flags = reduce(operator.xor, map( - lambda ext: getattr(misaka, 'EXT_' + ext.upper()), extensions), 0) - md = misaka.Markdown(Unofficial(), extensions=flags) + renderer = Unofficial() + md = misaka.Markdown(renderer, extensions=extensions) def inner(text): rv = md(text).rstrip("\n") @@ -88,7 +86,7 @@ class Unofficial(misaka.HtmlRenderer): to , compatible with Highlight.js. """ - def block_code(self, text, lang): + def blockcode(self, text, lang): lang = ' class="{0}"'.format(lang) if lang else '' return "
{0}
\n".format(text, lang)