当前位置: 首页>>代码示例>>Python>>正文


Python CommonMark.commonmark方法代码示例

本文整理汇总了Python中CommonMark.commonmark方法的典型用法代码示例。如果您正苦于以下问题:Python CommonMark.commonmark方法的具体用法?Python CommonMark.commonmark怎么用?Python CommonMark.commonmark使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在CommonMark的用法示例。


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

示例1: render

# 需要导入模块: import CommonMark [as 别名]
# 或者: from CommonMark import commonmark [as 别名]
def render(self):
        """Pre-render text to Content.rendered."""
        text = self.get_and_linkify_tags()
        rendered = commonmark(text).strip()
        rendered = process_text_links(rendered)
        if self.is_nsfw:
            rendered = make_nsfw_safe(rendered)
        if self.show_preview:
            if self.oembed:
                rendered = "%s<br>%s" % (
                    rendered, self.oembed.oembed
                )
            if self.opengraph:
                rendered = "%s%s" % (
                    rendered,
                    render_to_string("content/_og_preview.html", {"opengraph": self.opengraph})
                )
        self.rendered = rendered
        Content.objects.filter(id=self.id).update(rendered=rendered) 
开发者ID:jaywink,项目名称:socialhome,代码行数:21,代码来源:models.py

示例2: toHTML

# 需要导入模块: import CommonMark [as 别名]
# 或者: from CommonMark import commonmark [as 别名]
def toHTML(self,md,metadata,html,generateTitle=False):

      uri = self.weburi + metadata['published'][0]

      print('<article xmlns="http://www.w3.org/1999/xhtml" vocab="{}" typeof="{}" resource="{}">'.format(self.vocab,self.typeof,uri),file=html)
   
      print('<script type="application/json+ld">',file=html)
      print('{\n"@context" : "http://schema.org/",',file=html)
      print('"@id" : "{}",'.format(uri),file=html)
      print('"headline" : "{}",'.format(metadata['title'][0]),file=html)
      print('"datePublished" : "{}",'.format(metadata['published'][0]),file=html)
      print('"dateModified" : "{}",'.format(metadata['updated'][0]),file=html)
      if ("keywords" in metadata):
         print('"keywords" : [{}],'.format(','.join(['"' + m + '"' for m in metadata['keywords']])),file=html)
      html.write('"author" : [ ')
      for index,author in enumerate(metadata['author']):
         if (index>0):
            html.write(', ')
         html.write('{{ "@type" : "Person", "name" : "{}" }}'.format(author))
      html.write(']\n')
      print('}',file=html)
      print('</script>',file=html)

      if generateTitle:
         print("<h1>{}</h1>".format(escape(metadata['title'][0],quote=False)),file=html)

      print(CommonMark.commonmark(md),file=html)

      print('</article>',file=html) 
开发者ID:alexmilowski,项目名称:duckpond,代码行数:31,代码来源:article.py

示例3: markdown

# 需要导入模块: import CommonMark [as 别名]
# 或者: from CommonMark import commonmark [as 别名]
def markdown(content):
    """
    A Django template filter to render the given content as Markdown.
    """
    return CommonMark.commonmark(content) 
开发者ID:mozilla,项目名称:telemetry-analysis-service,代码行数:7,代码来源:templatetags.py

示例4: markdown

# 需要导入模块: import CommonMark [as 别名]
# 或者: from CommonMark import commonmark [as 别名]
def markdown(s):
    tainted_html = CommonMark.commonmark(s)
    safe_html = bleach.clean(tainted_html,
                             tags=ALLOWED_TAGS,
                             attributes=ALLOWED_ATTRIBUTES,
                             styles=ALLOWED_STYLES)
    return safe_html 
开发者ID:armadillica,项目名称:pillar,代码行数:9,代码来源:markdown.py

示例5: ifttt_maker

# 需要导入模块: import CommonMark [as 别名]
# 或者: from CommonMark import commonmark [as 别名]
def ifttt_maker(message: Message):
    """
    Fire a ifttt Maker event.

    You can trigger ifttt recipes using this command. Create recipes first
    using the `Maker Channel <https://ifttt.com/maker>`_ and then add your Maker
    key using the :code:`/pset ifttt_maker_key your_key` command.

    Here's how you could trigger an email event::

        /ifttt email

    Regarding variables: Value1 refers to the raw input data, Value2 refers to an HTML
    version, and Value3 is a Markdown and HTML free version.

    """
    parts = message.content.strip().split(" ", 1)
    if len(parts) == 1:
        event_name, data = parts[0], ""
    else:
        event_name, data = parts

    if not EVENT_NAME_RE.search(event_name):
        raise CommandError("Invalid event name. Only alphanumeric, dash, space, and underscore letters are allowed.")

    try:
        key = await prefs_manager.get(maker_key, message.author)
    except KeyError:
        raise CommandError("Set your Maker key with /pset ifttt_maker_key your_key first.")

    html = CommonMark.commonmark(data)
    text = strip_html(html)

    r = await http.post("https://maker.ifttt.com/trigger/{}/with/key/{}".format(event_name, key), data=json.dumps({
        "value1": data,
        "value2": html,
        "value3": text,
    }), headers=(('Content-Type', 'application/json'),), require_success=False)

    try:
        response = r.json()
        if 'errors' in response:
            raise CommandError("ifttt says: " + "\n".join([error['message'] for error in response['errors']]))
    except JSONDecodeError:
        pass

    return r.text() 
开发者ID:sk89q,项目名称:plumeria,代码行数:49,代码来源:ifttt.py


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