當前位置: 首頁>>代碼示例>>Python>>正文


Python misaka.Markdown方法代碼示例

本文整理匯總了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 
開發者ID:richardchien,項目名稱:blog-a,代碼行數:24,代碼來源:util.py

示例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 -------- 
開發者ID:eenot,項目名稱:bbs,代碼行數:20,代碼來源:bbstag.py

示例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 
開發者ID:miyakogi,項目名稱:wdom,代碼行數:10,代碼來源:markdown_simple.py

示例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) 
開發者ID:eenot,項目名稱:bbs,代碼行數:31,代碼來源:bbstag.py

示例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) 
開發者ID:Weasyl,項目名稱:weasyl,代碼行數:6,代碼來源:text.py

示例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))) 
開發者ID:miyakogi,項目名稱:wdom,代碼行數:47,代碼來源:markdown_simple.py


注:本文中的misaka.Markdown方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。