• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python mistune.escape函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中mistune.escape函数的典型用法代码示例。如果您正苦于以下问题:Python escape函数的具体用法?Python escape怎么用?Python escape使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了escape函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: image

    def image(self, src, title, text):
        """Rendering a image with title and text

        :param src: source link of the image with optional dimensions qualifier in format ' =<width>x[height]'.
        :param title: title text of the image.
        :param text: alt text of the image.
        """
        if src.startswith('javascript:'):
            src = ''
        dimensions = ''
        if ' ' in src:
            src, ext = src.split(' ', 1)
            size = re.search(r"=(?P<width>\d+)x(?P<height>\d*)", ext)
            if size:
                dimensions = ' width="%d"' % int(size.group('width'))
                if size.group('height'):
                    dimensions += ' height="%d"' % int(size.group('height'))
        text = mistune.escape(text, quote=True)
        if title:
            title = ' title="%s"' % mistune.escape(title, quote=True)
        else:
            title = ''
        html = '<img src="%s" alt="%s"%s%s />' % (src, text, title, dimensions)
        if dimensions:
            html = '<a href="%s">%s</a>' % (src, html)
        return html
开发者ID:3cky,项目名称:marcus,代码行数:26,代码来源:markdown.py


示例2: block_html

 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,项目名称:site,代码行数:28,代码来源:__init__.py


示例3: block_code

 def block_code(self, code, lang=""):
     code = code.rstrip('\n')
     if not lang:
         code = mistune.escape(code, smart_amp=False)
         return '<pre><code>%s\n</code></pre>\n' % code
     code = mistune.escape(code, quote=True, smart_amp=False)
     return '<pre><code class="hljs %s">%s\n</code></pre>\n' % (lang, code)
开发者ID:eatonphil,项目名称:eatonphil.com,代码行数:7,代码来源:build.py


示例4: block_code

 def block_code(self, code, lang):
     html = ""
     if lang:
         html = '\n<div class="highlight"><pre><code class="%s">%s</code></pre></div>\n' % \
                (lang, mistune.escape(code))
         return html
     html = '\n<div class="highlight"><pre><code>%s</code></pre></div>\n' % mistune.escape(code)
     return html
开发者ID:madflojo,项目名称:blog,代码行数:8,代码来源:hamerkop.py


示例5: parse_image_link

 def parse_image_link(self, m):
     link = mistune.escape(m.group(0).strip(), quote=True)
     title = mistune.escape(m.group('image_name').strip(), quote=True)
     self.tokens.append({
         'type': 'image_link',
         'src': link,
         'title': title,
         'text': title
     })
开发者ID:Uniquode,项目名称:Spirit,代码行数:9,代码来源:block.py


示例6: block_code

    def block_code(self, code, lang=None) -> str:

        if not lang:
            return '\n<pre><code>{:s}</code></pre>\n'.format(mistune.escape(code))

        try:
            lexer = get_lexer_by_name(lang, stripall=False)
        except ClassNotFound:
            return '\n<pre><code>{:s}</code></pre>\n'.format(mistune.escape(code))
        formatter = HtmlFormatter()
        return highlight(code, lexer, formatter)
开发者ID:django-tutorial,项目名称:shortlink,代码行数:11,代码来源:markdown.py


示例7: image

 def image(self, src, title, text):
     if src.startswith('javascript:'):
         src = ''
     text = mistune.escape(text, quote=True)
     if title:
         title = mistune.escape(title, quote=True)
         html = '<img class="img-responsive center-block" src="%s" alt="%s" title="%s"' % (src, text, title)
     else:
         html = '<img class="img-responsive center-block" src="%s" alt="%s"' % (src, text)
     if self.options.get('use_xhtml'):
         return '%s />' % html
     return '%s>' % html
开发者ID:abhijitmamarde,项目名称:MarkDownBlog,代码行数:12,代码来源:markdown.py


示例8: block_code

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:mikej165,项目名称:mistune-contrib,代码行数:14,代码来源:highlight.py


示例9: inline_html

    def inline_html(self, html):
        """Rendering span level pure html content.

        :param html: text content of the html snippet.
        """
        # use beautiful soup to parse and read element name, attributes
        soup = BeautifulSoup(html, 'lxml')
        # only expect one element here
        # NOTE: using xml parser had inconsistent results; using lxml
        # wraps contents inside html body tags, so access content there
        element = soup.html.body.contents[0]

        text_content = element.string or ''

        if element.name in ['i', 'em']:
            return '<emph rend="italic">%s</emph>' % text_content
        if element.name in ['b', 'strong']:
            return '<emph rend="bold">%s</emph>' % text_content
        if element.name == 'a':
            # convert name anchor to <anchor xml:id="###"/>
            # **preliminary**  (anchor not valid in all contexts)
            if element.get('name', None) or element.get('id', None):
                el_id = element.get('id', None) or element.get('name', None)
                return '<anchor xml:id="%s">%s</anchor>' % \
                    (el_id, text_content)

        if self.options.get('escape'):
            return mistune.escape(html)
        return html
开发者ID:WSULib,项目名称:readux,代码行数:29,代码来源:markdown_tei.py


示例10: image

    def image(self, src, title, text):
        """Rendering a image with title and text.

        :param src: source link of the image.
        :param title: title text of the image.
        :param text: alt text of the image.
        """
        if src.startswith('javascript:'):
            src = ''
        text = mistune.escape(text, quote=True)
        # markdown doesn't include mimetype, but it's required in TEI
        # infer mimetype based on image suffix in the url
        image_suffix = (src.rsplit('.', 1)[-1])
        mimetype = "image/*"
        if image_suffix in ['gif', 'png', 'jpeg']:
            mimetype = 'image/%s' % image_suffix
        elif image_suffix == 'jpg':
            mimetype = 'image/jpeg'
        tag = '<media mimetype="%s" url="%s">' % (mimetype, src)
        if title or text:
            desc_parts = ['<desc>']
            if title:
                desc_parts.append('<head>%s</head>' % title)
            if text:
                desc_parts.append('<p>%s</p>' % text)
            desc_parts.append('</desc>')
            tag += ''.join(desc_parts)
        tag += '</media>'
        return tag
开发者ID:WSULib,项目名称:readux,代码行数:29,代码来源:markdown_tei.py


示例11: codespan

    def codespan(self, text):
        """Rendering inline `code` text.

        :param text: text content for inline code.
        """
        text = mistune.escape(text.rstrip(), smart_amp=False)
        return '<code>%s</code>' % text
开发者ID:WSULib,项目名称:readux,代码行数:7,代码来源:markdown_tei.py


示例12: block_code

 def block_code(self, code, lang=None):
     code = code.rstrip('\n')
     code = mistune.escape(code, smart_amp=False)
     res = '<pre class="cn literal-block" id="cn%s">%s\n</pre>\n' % (
         self.cn, code)
     self.cn += 1
     return res
开发者ID:dongweiming,项目名称:aiglos,代码行数:7,代码来源:run.py


示例13: block_code

 def block_code(self, code, lang=None):
     if not lang:
         return '\n<pre><code>{code}</code></pre>\n'.format(code=mistune.escape(code))
     lexer = get_lexer_by_name(lang, stripall=True)
     formatter = HtmlFormatter(noclasses=True)
     text = highlight(code, lexer, formatter)
     return text.replace('class="highlight" ', '')
开发者ID:messense,项目名称:everbean,代码行数:7,代码来源:markdown.py


示例14: block_code

 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 = HtmlFormatter()
     return highlight(code, lexer, formatter)
开发者ID:BonjourChen,项目名称:myBlog,代码行数:7,代码来源:models.py


示例15: embed

 def embed(self, link, title, text):
     if link.startswith('javascript:'):
         link = ''
     if not title:
         return '<a href="%s" class="embed">%s</a>' % (link, text)
     title = mistune.escape(title, quote=True)
     return '<a href="%s" title="%s" class="embed">%s</a>' % (link, title, text)
开发者ID:Kidun,项目名称:memrise2anki-extension,代码行数:7,代码来源:markdown.py


示例16: block_code

 def block_code(self, text, lang):
      if not lang:
          return u'\n<pre><code>%s</code></pre>\n' % \
              mistune.escape(text.strip())
      lexer = get_lexer_by_name(lang, stripall=True)
      formatter = CodeHtmlFormatter()
      return highlight(text, lexer, formatter)
开发者ID:icersong,项目名称:misaka_md2html,代码行数:7,代码来源:misaka_md2html.py


示例17: autolink

 def autolink(self, link, is_email=False):
     text = link = escape(link)
     if is_email:
         link = 'mailto:%s' % link
         ltype = 'email'
     else:
         ltype = 'link'
     return ltype, link, text
开发者ID:chintal,项目名称:tendril,代码行数:8,代码来源:markdown.py


示例18: block_code

 def block_code(self, code, lang=None):
     code = code.rstrip('\n')
     if not lang:
         code = mistune.escape(code, smart_amp=False)
         return '<pre><code>{0}\n</code></pre>\n'.format(code)
     lexer = get_lexer_by_name(lang, stripall=True)
     formatter = HtmlFormatter(cssclass='highlight ' + lang)
     return highlight(code, lexer, formatter)
开发者ID:SERHIISV,项目名称:blog,代码行数:8,代码来源:models.py


示例19: block_code

 def block_code(self, code, lang):
     if not lang:
         return "\n<pre><code>{}</code></pre>\n".format(
             mistune.escape(code)
         )
     lexer = get_lexer_by_name(lang, stripall=True)
     formatter = html.HtmlFormatter()
     return highlight(code, lexer, formatter)
开发者ID:Ayrx,项目名称:Ayrx.github.io,代码行数:8,代码来源:generate.py


示例20: block_code

 def block_code(self, code, lang):
     if not lang:
         return '<pre><code>{0}</code></pre>'.format(escape(code))
     lexer = get_lexer_by_name(lang, stripall=True)
     formatter = HtmlFormatter(
         linenos='table',
         style='railscasts',
         cssclass='b-codeblock')
     return highlight(code, lexer, formatter)
开发者ID:spryle,项目名称:james.spry-leverton.com,代码行数:9,代码来源:formats.py



注:本文中的mistune.escape函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python mistune.markdown函数代码示例发布时间:2022-05-27
下一篇:
Python mistrequests.MistRequests类代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap