本文整理汇总了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
示例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
示例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
示例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)
示例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)
示例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)
示例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(' ', '')
示例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)
示例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())
示例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)
示例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
示例12: __call__
# 需要导入模块: import mistune [as 别名]
# 或者: from mistune import Markdown [as 别名]
def __call__(self, text):
return super(Markdown, self).__call__(text).strip()
示例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()
示例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)
示例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
# 用于处理嵌套目录