当前位置: 首页>>代码示例>>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;未经允许,请勿转载。