本文整理汇总了Python中misaka.Markdown方法的典型用法代码示例。如果您正苦于以下问题:Python misaka.Markdown方法的具体用法?Python misaka.Markdown怎么用?Python misaka.Markdown使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类misaka
的用法示例。
在下文中一共展示了misaka.Markdown方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: render_md
# 需要导入模块: import misaka [as 别名]
# 或者: from misaka import Markdown [as 别名]
def render_md(md_str):
"""
Render a markdown string
:param md_str: markdown string to render
:return: html text
"""
return misaka.Markdown(
renderer,
extensions=('fenced-code',
'tables',
'footnotes',
'autolink',
'strikethrough',
'underline',
'highlight',
'quote',
'superscript')
)(md_str)
# regex to match the post file with correct format
示例2: time_to_now
# 需要导入模块: import misaka [as 别名]
# 或者: from misaka import Markdown [as 别名]
def time_to_now(value):
now = timezone.now()
delta = now - value
if delta.days > 365:
return '%s ??' % str(delta.days / 365)
if delta.days > 30:
return '%s ??' % str(delta.days / 30)
if delta.days > 0:
return '%s ??' % str( delta.days)
if delta.seconds > 3600:
return '%s ???' % str(delta.seconds / 3600)
if delta.seconds > 60:
return '%s ???' % str(delta.seconds / 60)
return '??'
# --------- filter ---------
# -------- Markdown Extension --------
示例3: sample_page
# 需要导入模块: import misaka [as 别名]
# 或者: from misaka import Markdown [as 别名]
def sample_page(**kwargs):
get_document().register_theme(default)
app = Div(style='width: 90vw; margin: auto')
title = H1('Simple Markdown Editor', class_='text-center')
app.appendChild(title)
app.appendChild(Hr())
app.appendChild(Editor())
return app
示例4: my_markdown
# 需要导入模块: import misaka [as 别名]
# 或者: from misaka import Markdown [as 别名]
def my_markdown(value, flag):
extensions = (
misaka.EXT_NO_INTRA_EMPHASIS | misaka.EXT_FENCED_CODE | misaka.EXT_AUTOLINK |
misaka.EXT_TABLES | misaka.EXT_STRIKETHROUGH | misaka.EXT_SUPERSCRIPT
)
# ???????????????Markdown??
if flag == 'comment':
renderer = CommentRenderer(flags=misaka.HTML_ESCAPE | misaka.HTML_HARD_WRAP)
else:
renderer = TopicRenderer(flags=misaka.HTML_ESCAPE | misaka.HTML_HARD_WRAP)
md = misaka.Markdown(renderer, extensions=extensions)
md = md.render(force_unicode(value))
# @??????
team_name_pattern = re.compile('(?<[email protected])([0-9a-zA-Z_.]+)', re.UNICODE)
at_name_list = set(re.findall(team_name_pattern, md))
if at_name_list:
for at_name in at_name_list:
try:
at_user = User.objects.get(username=at_name)
if at_user:
md = md.replace('@'+at_name,'<a href="%s" class="at_user">@%s</a>' % (reverse("user:user",args=(at_user.id,)),at_name))
except:
pass
return mark_safe(md)
示例5: _markdown
# 需要导入模块: import misaka [as 别名]
# 或者: from misaka import Markdown [as 别名]
def _markdown(target):
renderer = WeasylRenderer(MISAKA_FORMAT)
markdown = misaka.Markdown(renderer, MISAKA_EXT)
return markdown.render(target)
示例6: __init__
# 需要导入模块: import misaka [as 别名]
# 或者: from misaka import Markdown [as 别名]
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.md = m.Markdown(HighlighterRenderer(),
extensions=('fenced-code',))
self.css = Style(parent=self)
self.setAttribute('style', 'height: 80vh;')
editor_col = Col6(parent=self)
self.editor = Textarea(parent=editor_col)
self.editor.setAttribute('style', 'height: 80vh')
viewer_col = Col6(parent=self)
self.style_selector = Select()
styles = sorted(get_all_styles())
styles.remove('default')
self.style_selector.appendChild(
Option('default', value='default', selected=True))
for style in styles:
self.style_selector.appendChild(Option(style, value=style))
self.style_selector.addEventListener(
'change', lambda event: self.set_style(event.currentTarget.value))
self.viewer = Div()
self.viewer.setAttribute(
'style',
'''
height: 100%;
min-height: 80vh;
padding: 1em 2em;
border: 1px solid #ddd;
border-radius: 3px;
''',
)
viewer_col.appendChild(self.style_selector)
viewer_col.appendChild(self.viewer)
self.editor.addEventListener('input', self.render)
self.set_style('default')
self.editor.textContent = src
# TIPS: Wen just showing HTML, `appendChild(RawHtmlNode)` is better
# than innerHTML on performance since it skips parse process.
self.viewer.appendChild(RawHtmlNode(self.md(src)))