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


Python mistune.escape方法代碼示例

本文整理匯總了Python中mistune.escape方法的典型用法代碼示例。如果您正苦於以下問題:Python mistune.escape方法的具體用法?Python mistune.escape怎麽用?Python mistune.escape使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在mistune的用法示例。


在下文中一共展示了mistune.escape方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: block_code

# 需要導入模塊: import mistune [as 別名]
# 或者: from mistune import escape [as 別名]
def block_code(uuid, text, lang, inlinestyles=False, linenos=False):
    """Renders a code block"""
    if is_plant_uml(text, lang):
        fName = Settings().plantUMLCache.getResource(text, uuid)
        if fName is None:
            return '<br/><img src="cdm-image:na50.png"><br/>\n'
        return '<br/><img src="plantuml:' + fName + '"><br/>\n'

    lexer = get_lexer(text, lang)
    if lexer:
        try:
            formatter = HtmlFormatter(noclasses=inlinestyles, linenos=linenos)
            code = highlight(text, lexer, formatter)
            return ''.join([PRE_WRAP_START, '<pre>',
                            code.replace('125%', '100%'), '</pre>',
                            PRE_WRAP_END, '\n'])
        except:
            pass

    return ''.join([PRE_WRAP_START, '<pre>', mistune.escape(text),
                    '</pre>', PRE_WRAP_END, '\n']) 
開發者ID:SergeySatskiy,項目名稱:codimension,代碼行數:23,代碼來源:md.py

示例2: block_code

# 需要導入模塊: import mistune [as 別名]
# 或者: from mistune import escape [as 別名]
def block_code(self, code, lang=None):
        """Rendering block level code. ``pre > code``.

        :param code: text content of the code block.
        :param lang: language of the given code.
        """
        code = code.rstrip('\n')  # 去掉尾部的換行符
        # 如果沒有lang, 就返回代碼塊
        if not lang:
            code = mistune.escape(code)
            return '<pre><code>%s\n</code></pre>\n' % code

        # 給代碼加上高亮  例如: lang='python'的話
        # ```python
        #   print('666')
        # ```
        try:
            lexer = get_lexer_by_name(lang, stripall=True)
        except ClassNotFound:
            # 如果lang是不合法, 沒有匹配到, 就設置為python
            lexer = get_lexer_by_name('python', stripall=True)
        formatter = html.HtmlFormatter()  # linenos=True
        return highlight(code, lexer, formatter) 
開發者ID:enjoy-binbin,項目名稱:Django-blog,代碼行數:25,代碼來源:mistune_markdown.py

示例3: block_code

# 需要導入模塊: import mistune [as 別名]
# 或者: from mistune import escape [as 別名]
def block_code(text, lang, inlinestyles=False, linenos=False):
    if not lang:
        text = text.strip()
        return u'<pre><code>%s</code></pre>\n' % mistune.escape(text)

    try:
        lexer = get_lexer_by_name(lang, stripall=True)
        formatter = HtmlFormatter(
            noclasses=inlinestyles, linenos=linenos
        )
        code = highlight(text, lexer, formatter)
        if linenos:
            return '<div class="highlight-wrapper">%s</div>\n' % code
        return code
    except:
        return '<pre class="%s"><code>%s</code></pre>\n' % (
            lang, mistune.escape(text)
        ) 
開發者ID:lepture,項目名稱:mistune-contrib,代碼行數:20,代碼來源:highlight.py

示例4: from_text

# 需要導入模塊: import mistune [as 別名]
# 或者: from mistune import escape [as 別名]
def from_text(txt):
    def replace(match):
        txt = match.group()
        if '\n' in txt:
            return '<br>' * txt.count('\n')
        else:
            return '&nbsp;' * txt.count(' ')

    tpl = '<p>%s</p>'
    htm = escape(txt)
    htm = fromstring(tpl % htm)
    fix_links(htm)
    htm = tostring(htm, encoding='unicode')
    htm = htm[3:-4]
    htm = re.sub('(?m)((\r?\n)+| [ ]+|^ )', replace, htm)
    htm = tpl % htm
    return htm 
開發者ID:naspeh,項目名稱:mailur,代碼行數:19,代碼來源:html.py

示例5: autolink

# 需要導入模塊: import mistune [as 別名]
# 或者: from mistune import escape [as 別名]
def autolink(self, link, is_email=False):
        text = link = mistune.escape(link)
        if is_email:
            link = 'mailto:%s' % link
        return '<a href="%s"%s>%s</a>' % (link, self._link_rel(link), text) 
開發者ID:DMOJ,項目名稱:online-judge,代碼行數:7,代碼來源:__init__.py

示例6: link

# 需要導入模塊: import mistune [as 別名]
# 或者: from mistune import escape [as 別名]
def link(self, link, title, text):
        link = mistune.escape_link(link)
        if not title:
            return '<a href="%s"%s>%s</a>' % (link, self._link_rel(link), text)
        title = mistune.escape(title, quote=True)
        return '<a href="%s" title="%s"%s>%s</a>' % (link, title, self._link_rel(link), text) 
開發者ID:DMOJ,項目名稱:online-judge,代碼行數:8,代碼來源:__init__.py

示例7: block_code

# 需要導入模塊: import mistune [as 別名]
# 或者: from mistune import escape [as 別名]
def block_code(self, code, lang=None):
        if not lang:
            return '\n<pre><code>%s</code></pre>\n' % mistune.escape(code).rstrip()
        return highlight_code(code, lang) 
開發者ID:DMOJ,項目名稱:online-judge,代碼行數:6,代碼來源:__init__.py

示例8: block_html

# 需要導入模塊: import mistune [as 別名]
# 或者: from mistune import escape [as 別名]
def block_html(self, html):
        if self.texoid and html.startswith('<latex'):
            attr = html[6:html.index('>')]
            latex = html[html.index('>') + 1:html.rindex('<')]
            latex = self.parser.unescape(latex)
            result = self.texoid.get_result(latex)
            if not result:
                return '<pre>%s</pre>' % mistune.escape(latex, smart_amp=False)
            elif 'error' not in result:
                img = ('''<img src="%(svg)s" onerror="this.src='%(png)s';this.onerror=null"'''
                       'width="%(width)s" height="%(height)s"%(tail)s>') % {
                    'svg': result['svg'], 'png': result['png'],
                    'width': result['meta']['width'], 'height': result['meta']['height'],
                    'tail': ' /' if self.options.get('use_xhtml') else '',
                }
                style = ['max-width: 100%',
                         'height: %s' % result['meta']['height'],
                         'max-height: %s' % result['meta']['height'],
                         'width: %s' % result['meta']['height']]
                if 'inline' in attr:
                    tag = 'span'
                else:
                    tag = 'div'
                    style += ['text-align: center']
                return '<%s style="%s">%s</%s>' % (tag, ';'.join(style), img, tag)
            else:
                return '<pre>%s</pre>' % mistune.escape(result['error'], smart_amp=False)
        return super(AwesomeRenderer, self).block_html(html) 
開發者ID:DMOJ,項目名稱:online-judge,代碼行數:30,代碼來源:__init__.py

示例9: markdown

# 需要導入模塊: import mistune [as 別名]
# 或者: from mistune import escape [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

示例10: math

# 需要導入模塊: import mistune [as 別名]
# 或者: from mistune import escape [as 別名]
def math(self, math):
        if self.mathoid is None or not math:
            return r'\(%s\)' % mistune.escape(str(math))
        return self.mathoid.inline_math(math) 
開發者ID:DMOJ,項目名稱:online-judge,代碼行數:6,代碼來源:math.py

示例11: display_math

# 需要導入模塊: import mistune [as 別名]
# 或者: from mistune import escape [as 別名]
def display_math(self, math):
        math = format_math(math)
        return self.get_result(r'\displaystyle ' + math) or r'\[%s\]' % escape(math) 
開發者ID:DMOJ,項目名稱:online-judge,代碼行數:5,代碼來源:mathoid.py

示例12: inline_math

# 需要導入模塊: import mistune [as 別名]
# 或者: from mistune import escape [as 別名]
def inline_math(self, math):
        math = format_math(math)
        return self.get_result(math) or r'\(%s\)' % escape(math) 
開發者ID:DMOJ,項目名稱:online-judge,代碼行數:5,代碼來源:mathoid.py

示例13: block_code

# 需要導入模塊: import mistune [as 別名]
# 或者: from mistune import escape [as 別名]
def block_code(self, code, lang):
        if not lang:
            return '\n<pre><code>%s</code></pre>\n' % \
                mistune.escape(code)
        lexer = get_lexer_by_name(lang, stripall=True)
        formatter = html.HtmlFormatter(noclasses=True)
        return highlight(code, lexer, formatter) 
開發者ID:naspeh,項目名稱:mailur,代碼行數:9,代碼來源:html.py

示例14: to_text

# 需要導入模塊: import mistune [as 別名]
# 或者: from mistune import escape [as 別名]
def to_text(htm):
    htm = fromstring(htm)
    return '\n'.join(escape(i) for i in htm.xpath('//text()') if i) 
開發者ID:naspeh,項目名稱:mailur,代碼行數:5,代碼來源:html.py

示例15: _clean_poll

# 需要導入模塊: import mistune [as 別名]
# 或者: from mistune import escape [as 別名]
def _clean_poll(self):
        name_raw = self.data['name']
        title_raw = self.data['title']
        min_raw = self.data['min']
        max_raw = self.data['max']
        close_at_raw = self.data['close']
        mode_raw = self.data['mode']

        poll = {
            'name': name_raw[:self._field_name.max_length]
        }

        if title_raw:
            title = mistune.escape(title_raw.strip(), quote=True)
            poll['title'] = title[:self._field_title.max_length]  # May be empty

        if min_raw:
            poll['choice_min'] = int(min_raw)

        if max_raw:
            poll['choice_max'] = int(max_raw)

        if close_at_raw:
            days = int(close_at_raw[:self.close_max_len])
            poll['close_at'] = timezone.now() + timezone.timedelta(days=days)

        if mode_raw:
            poll['mode'] = PollMode.BY_NAME[mode_raw]

        self.cleaned_data['poll'] = poll 
開發者ID:nitely,項目名稱:Spirit,代碼行數:32,代碼來源:poll.py


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