Ejemplo n.º 1
0
    def generate_article_html(md_text, font_icons=False, highlight=False):
        parser = markdown_it.MarkdownIt().enable('table')
        html = parser.render(md_text)

        content_html = HTMLGen._apply_headers_anchors(html)

        toc = HTMLGen._extract_toc(content_html)
        toc_html = HTMLGen._generate_toc_html(toc)
        template = env.get_template(ARTICLE_TEMPLATE_FILE.name)
        content_html = HTMLGen._apply_font_icons(content_html) if font_icons else content_html
        content_html = HTMLGen._apply_highlighting(content_html) if highlight else content_html
        html = template.render(content=content_html, toc=toc_html)

        return html, toc_html
Ejemplo n.º 2
0
def parser():
    return markdown_it.MarkdownIt("commonmark")
Ejemplo n.º 3
0
def test_markdown_it_py(benchmark, spec_text):
    import markdown_it

    parser = markdown_it.MarkdownIt("commonmark")
    benchmark.extra_info["version"] = markdown_it.__version__
    benchmark(parser.render, spec_text)
Ejemplo n.º 4
0
"""
Simple markdown parser which does not support nesting. Intended primarily
for use within the library, which attempts to handle emojies correctly,
since they seem to count as two characters and it's a bit strange.
"""
import re
import warnings
import markdown_it

from .helpers import add_surrogate, del_surrogate, within_surrogate, strip_text
from .. import _tl
from .._misc import tlobject


MARKDOWN = markdown_it.MarkdownIt().enable('strikethrough')
DELIMITERS = {
    _tl.MessageEntityBlockquote: ('> ', ''),
    _tl.MessageEntityBold: ('**', '**'),
    _tl.MessageEntityCode: ('`', '`'),
    _tl.MessageEntityItalic: ('_', '_'),
    _tl.MessageEntityStrike: ('~~', '~~'),
    _tl.MessageEntitySpoiler: ('||', '||'),
    _tl.MessageEntityUnderline: ('# ', ''),
}

# Not trying to be complete; just enough to have an alternative (mostly for inline underline).
# The fact headings are treated as underline is an implementation detail.
TAG_PATTERN = re.compile(r'<\s*(/?)\s*(\w+)')
HTML_TO_TYPE = {
    'i': ('em_close', 'em_open'),
    'em': ('em_close', 'em_open'),