From 7cdb47d8751b106414f85ec7409ece35f81c5d10 Mon Sep 17 00:00:00 2001 From: Steffen Prince Date: Thu, 29 Oct 2015 13:24:33 -0700 Subject: [PATCH] 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)