當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。