当前位置: 首页>>代码示例>>Python>>正文


Python mistune.Markdown方法代码示例

本文整理汇总了Python中mistune.Markdown方法的典型用法代码示例。如果您正苦于以下问题:Python mistune.Markdown方法的具体用法?Python mistune.Markdown怎么用?Python mistune.Markdown使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在mistune的用法示例。


在下文中一共展示了mistune.Markdown方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: md2html

# 需要导入模块: import mistune [as 别名]
# 或者: from mistune import Markdown [as 别名]
def md2html(text, styles=None, poster='', banner='', convert_list=True, ul_style='\u25CB'):
    md = Markdown()

    # 将markdown列表转化为带序号的普通段落(纯为适应微信中列表序号样式自动丢失的古怪现象)
    if convert_list:
        blocks = text.split('\n```')
        for i in range(0, len(blocks)):
            if i % 2 == 0:
                blocks[i] = re.sub(r'(\n\d+)(\.\s.*?)', r'\n\1\\\2', blocks[i])
                blocks[i] = re.sub(r'\n[\-\+\*](\s.*?)',
                                   u'\n\n{} \1'.format(ul_style), blocks[i])
            else:
                continue  # 跳过代码块内部内容
        text = '\n```'.join(blocks)

    inner_html = md(text)
    result = premailer.transform(pack_html(inner_html, styles, poster, banner))
    return result 
开发者ID:insula1701,项目名称:maxpress,代码行数:20,代码来源:maxpress.py

示例2: load_plugin

# 需要导入模块: import mistune [as 别名]
# 或者: from mistune import Markdown [as 别名]
def load_plugin(plugin_name, ast=False):
    _plugin = getattr(plugins, 'plugin_{}'.format(plugin_name))

    class TestPlugin(BaseTestCase):
        md = Markdown(
            renderer=HTMLRenderer(escape=False),
            plugins=[_plugin]
        )

    def test_ast_renderer(self):
        md = Markdown(renderer=AstRenderer(), plugins=[_plugin])
        data = fixtures.load_json(plugin_name + '.json')
        self.assertEqual(md(data['text']), data['tokens'])

    if ast:
        test_ast_renderer.__doc__ = 'Run {} ast renderer'.format(plugin_name)
        setattr(TestPlugin, 'test_ast_renderer', test_ast_renderer)

    TestPlugin.load_fixtures(plugin_name + '.txt')
    globals()['TestPlugin_' + plugin_name] = TestPlugin 
开发者ID:lepture,项目名称:mistune,代码行数:22,代码来源:test_plugins.py

示例3: renderMarkdown

# 需要导入模块: import mistune [as 别名]
# 或者: from mistune import Markdown [as 别名]
def renderMarkdown(uuid, text, fileName):
    """Renders the given text"""
    warnings = []
    errors = []
    renderedText = None
    try:
        renderer = CDMMarkdownRenderer(uuid, fileName)
        markdown = mistune.Markdown(renderer=renderer)
        renderedText = markdown(text)
    except Exception as exc:
        errors.append(str(exc))
    except:
        errors.append('Unknown markdown rendering exception')
    return renderedText, errors, warnings 
开发者ID:SergeySatskiy,项目名称:codimension,代码行数:16,代码来源:md.py

示例4: parse

# 需要导入模块: import mistune [as 别名]
# 或者: from mistune import Markdown [as 别名]
def parse(self, markdown_text, config):
        renderer = ParsingRenderer()
        markdown = mistune.Markdown(renderer=renderer)
        markdown(markdown_text)
        self.blocks = renderer.blocks
        self.headlines = renderer.headlines if renderer.headlines.strip() else u''
        self.tags = self.get_tags_line(markdown_text, config) 
开发者ID:BernhardWenzel,项目名称:markdown-search,代码行数:9,代码来源:markdown_parser.py

示例5: __init__

# 需要导入模块: import mistune [as 别名]
# 或者: from mistune import Markdown [as 别名]
def __init__(self, app):
        app.jinja_env.filters.setdefault('markdown', self.__call__)
        renderer = Renderer(escape=False, hard_wrap=True)
        self.markdown = mistune.Markdown(renderer=renderer) 
开发者ID:opendatateam,项目名称:udata,代码行数:6,代码来源:markdown.py

示例6: article_markdown

# 需要导入模块: import mistune [as 别名]
# 或者: from mistune import Markdown [as 别名]
def article_markdown(text):
    """ 对传入的text文本进行markdown """
    renderer = ArticleRenderer()
    markdown = mistune.Markdown(renderer=renderer)
    return markdown(text) 
开发者ID:enjoy-binbin,项目名称:Django-blog,代码行数:7,代码来源:mistune_markdown.py

示例7: test_toc

# 需要导入模块: import mistune [as 别名]
# 或者: from mistune import Markdown [as 别名]
def test_toc():
    toc = TocRenderer()
    md = mistune.Markdown(renderer=toc)
    toc.reset_toc()
    assert 'toc-0' in md.parse(text)
    rv = toc.render_toc(level=3)
    rv = rv.replace('\n', '').replace(' ', '')
    assert rv == expected.replace('\n', '').replace(' ', '') 
开发者ID:lepture,项目名称:mistune-contrib,代码行数:10,代码来源:test_toc.py

示例8: markdown

# 需要导入模块: import mistune [as 别名]
# 或者: from mistune import Markdown [as 别名]
def markdown(value, style, math_engine=None, lazy_load=False):
    styles = settings.MARKDOWN_STYLES.get(style, settings.MARKDOWN_DEFAULT_STYLE)
    escape = styles.get('safe_mode', True)
    nofollow = styles.get('nofollow', True)
    texoid = TEXOID_ENABLED and styles.get('texoid', False)
    math = getattr(settings, 'MATHOID_URL') and styles.get('math', False)
    bleach_params = styles.get('bleach', {})

    post_processors = []
    if styles.get('use_camo', False) and camo_client is not None:
        post_processors.append(camo_client.update_tree)
    if lazy_load:
        post_processors.append(lazy_load_processor)

    renderer = AwesomeRenderer(escape=escape, nofollow=nofollow, texoid=texoid,
                               math=math and math_engine is not None, math_engine=math_engine)
    markdown = mistune.Markdown(renderer=renderer, inline=AwesomeInlineLexer,
                                parse_block_html=1, parse_inline_html=1)
    result = markdown(value)

    if post_processors:
        tree = fragments_to_tree(result)
        for processor in post_processors:
            processor(tree)
        result = fragment_tree_to_str(tree)
    if bleach_params:
        result = get_cleaner(style, bleach_params).clean(result)
    return Markup(result) 
开发者ID:DMOJ,项目名称:online-judge,代码行数:30,代码来源:__init__.py

示例9: __init__

# 需要导入模块: import mistune [as 别名]
# 或者: from mistune import Markdown [as 别名]
def __init__(self):
        super().__init__()
        self._html_parser = TempyParser()
        self._markdown_parser = Markdown(renderer=TempyMarkdownRenderer()) 
开发者ID:Hrabal,项目名称:TemPy,代码行数:6,代码来源:t.py

示例10: setup

# 需要导入模块: import mistune [as 别名]
# 或者: from mistune import Markdown [as 别名]
def setup(cls):
        renderer = cls(escape=True, hard_wrap=True)
        return mistune.Markdown(renderer=renderer) 
开发者ID:sebst,项目名称:pythonic-news,代码行数:5,代码来源:news_extra.py

示例11: __init__

# 需要导入模块: import mistune [as 别名]
# 或者: from mistune import Markdown [as 别名]
def __init__(self, no_follow=True):
        renderer = Renderer(
            escape=True,
            hard_wrap=True,
            no_follow=no_follow
        )
        super(Markdown, self).__init__(
            renderer=renderer,
            block=BlockLexer,
            inline=InlineLexer,
            parse_block_html=False,
            parse_inline_html=False
        )

    # Override 
开发者ID:nitely,项目名称:Spirit,代码行数:17,代码来源:markdown.py

示例12: __call__

# 需要导入模块: import mistune [as 别名]
# 或者: from mistune import Markdown [as 别名]
def __call__(self, text):
        return super(Markdown, self).__call__(text).strip() 
开发者ID:nitely,项目名称:Spirit,代码行数:4,代码来源:markdown.py

示例13: parse_content

# 需要导入模块: import mistune [as 别名]
# 或者: from mistune import Markdown [as 别名]
def parse_content(renderer, content):
    lexer = PcbDrawInlineLexer(renderer)
    processor = mistune.Markdown(renderer=renderer, inline=lexer)
    processor(content)
    return renderer.output() 
开发者ID:yaqwsx,项目名称:PcbDraw,代码行数:7,代码来源:populate.py

示例14: __init__

# 需要导入模块: import mistune [as 别名]
# 或者: from mistune import Markdown [as 别名]
def __init__(self, evaluator, template=None):
        self.evaluator = evaluator

        if template is None:
            template = jinja_env().get_template(self.evaluator.TEMPLATE_NAME)
        elif isinstance(template, Path):
            template = Template(template.read_text())
        elif isinstance(template, str):
            template = Template(template)

        rendered = template.render(e=evaluator)
        md = mistune.Markdown()
        self.rendered = md(rendered) 
开发者ID:edublancas,项目名称:sklearn-evaluation,代码行数:15,代码来源:report.py

示例15: report_error

# 需要导入模块: import mistune [as 别名]
# 或者: from mistune import Markdown [as 别名]
def report_error(func):
    def wrapper(*args, **kwargs):
        try:
            result = func(*args, **kwargs)
            return result
        except Exception as e:
            print('错误: {}'.format(e))
            input('提示:运行前请将所有要转换的Markdown文档放入temp目录中\n'
                  '请按回车键退出程序:')

    return wrapper

# 用于处理嵌套目录 
开发者ID:insula1701,项目名称:maxpress,代码行数:15,代码来源:maxpress.py


注:本文中的mistune.Markdown方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。