|
|
@ -2,7 +2,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
from __future__ import unicode_literals
|
|
|
|
from __future__ import unicode_literals
|
|
|
|
|
|
|
|
|
|
|
|
import operator
|
|
|
|
|
|
|
|
import pkg_resources
|
|
|
|
import pkg_resources
|
|
|
|
|
|
|
|
|
|
|
|
from distutils.version import LooseVersion as Version
|
|
|
|
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_VERSION = Version(pkg_resources.get_distribution("html5lib").version)
|
|
|
|
HTML5LIB_SIMPLETREE = Version("0.95")
|
|
|
|
HTML5LIB_SIMPLETREE = Version("0.95")
|
|
|
|
|
|
|
|
|
|
|
|
from isso.compat import reduce
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import html5lib
|
|
|
|
import html5lib
|
|
|
|
from html5lib.sanitizer import HTMLSanitizer
|
|
|
|
from html5lib.sanitizer import HTMLSanitizer
|
|
|
|
from html5lib.serializer import HTMLSerializer
|
|
|
|
from html5lib.serializer import HTMLSerializer
|
|
|
@ -23,7 +20,8 @@ def Sanitizer(elements, attributes):
|
|
|
|
|
|
|
|
|
|
|
|
class Inner(HTMLSanitizer):
|
|
|
|
class Inner(HTMLSanitizer):
|
|
|
|
|
|
|
|
|
|
|
|
# attributes found in Sundown's HTML serializer [1] except for <img> tag,
|
|
|
|
# attributes found in Sundown's HTML serializer [1]
|
|
|
|
|
|
|
|
# except for <img> tag,
|
|
|
|
# because images are not generated anyways.
|
|
|
|
# because images are not generated anyways.
|
|
|
|
#
|
|
|
|
#
|
|
|
|
# [1] https://github.com/vmg/sundown/blob/master/html/html.c
|
|
|
|
# [1] https://github.com/vmg/sundown/blob/master/html/html.c
|
|
|
@ -65,11 +63,11 @@ def sanitize(tokenizer, document):
|
|
|
|
return serializer.render(stream)
|
|
|
|
return serializer.render(stream)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def Markdown(extensions=("strikethrough", "superscript", "autolink")):
|
|
|
|
def Markdown(extensions=("strikethrough", "superscript", "autolink",
|
|
|
|
|
|
|
|
"fenced-code")):
|
|
|
|
|
|
|
|
|
|
|
|
flags = reduce(operator.xor, map(
|
|
|
|
renderer = Unofficial()
|
|
|
|
lambda ext: getattr(misaka, 'EXT_' + ext.upper()), extensions), 0)
|
|
|
|
md = misaka.Markdown(renderer, extensions=extensions)
|
|
|
|
md = misaka.Markdown(Unofficial(), extensions=flags)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def inner(text):
|
|
|
|
def inner(text):
|
|
|
|
rv = md(text).rstrip("\n")
|
|
|
|
rv = md(text).rstrip("\n")
|
|
|
@ -88,7 +86,7 @@ class Unofficial(misaka.HtmlRenderer):
|
|
|
|
to <code class="$lang">, compatible with Highlight.js.
|
|
|
|
to <code class="$lang">, compatible with Highlight.js.
|
|
|
|
"""
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
|
|
def block_code(self, text, lang):
|
|
|
|
def blockcode(self, text, lang):
|
|
|
|
lang = ' class="{0}"'.format(lang) if lang else ''
|
|
|
|
lang = ' class="{0}"'.format(lang) if lang else ''
|
|
|
|
return "<pre><code{1}>{0}</code></pre>\n".format(text, lang)
|
|
|
|
return "<pre><code{1}>{0}</code></pre>\n".format(text, lang)
|
|
|
|
|
|
|
|
|
|
|
|