Exemplo n.º 1
0
def convert(text):
    inline = HighlightInlineLexer(mistune.Renderer(),
                                  hard_wrap=True,
                                  parse_inline_html=True)
    inline.enable_highlight()
    block = SimpleTableBlockLexer(mistune.BlockGrammar())
    block.enable_simple_table()
    markdown = SimpleTableMarkdown(inline=inline, block=block)
    return markdown(text)
Exemplo n.º 2
0
    def __init__(self):
        treeRenderer = JuloDocRenderer()
        blockLexer = mistune.BlockLexer(
            mistune.BlockGrammar())  #JuloDocBlockLexer()
        inlineLexer = JuloDocInlineLexer(treeRenderer)

        super(JuloParser, self).__init__(renderer=treeRenderer,
                                         inline=inlineLexer,
                                         block=blockLexer)
Exemplo n.º 3
0
):
    pass


class FluffyMarkdownBlockLexer(
        mistune.BlockLexer,
        HtmlCommentsBlockLexerMixin,
):
    pass


_renderer = FluffyMarkdownRenderer(
    escape=True,
    hard_wrap=False,
)

_inline = FluffyMarkdownInlineLexer(_renderer)
_inline.enable_html_comments()

_block = FluffyMarkdownBlockLexer(mistune.BlockGrammar())
_block.enable_html_comments()


@app.template_filter()
def markdown(text):
    return mistune.Markdown(
        renderer=_renderer,
        inline=_inline,
        block=_block,
    )(text)
Exemplo n.º 4
0
        HtmlCommentsLexerMixin,
):
    pass


_renderer = OcfMarkdownRenderer(
    escape=True,
    hard_wrap=False,
)

_inline = OcfMarkdownInlineLexer(_renderer)
_inline.enable_html_comments()
_inline.enable_django_links()
_inline.enable_backslash_line_breaks()

_block = OcfMarkdownBlockLexer(mistune.BlockGrammar())
_block.enable_html_comments()

_markdown = mistune.Markdown(
    renderer=_renderer,
    inline=_inline,
    block=_block,
)


def markdown(text: str) -> mistune.Markdown:
    _renderer.reset_toc()
    return _markdown(text)


def text_and_meta(f: Any) -> Tuple[str, Any]:
Exemplo n.º 5
0
# coding: utf-8
"""
    writeup.parser
    ~~~~~~~~~~~~~~

    Parse a markdown file into a Post.

    :copyright: (c) 2013 by Hsiaoming Yang
"""

import re
import yaml
import mistune as m
from ._compat import to_unicode

rules = m.BlockGrammar()


def parse(filepath):
    """Read a file and parse it to a dict."""

    with open(filepath, 'r') as f:
        content = f.read()

    try:
        meta = parse_text(content)
    except:
        return None

    meta['filepath'] = filepath
    return meta