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


Python commonmark.commonmark方法代碼示例

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


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

示例1: 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

示例2: save

# 需要導入模塊: import commonmark [as 別名]
# 或者: from commonmark import commonmark [as 別名]
def save(self, *args, **kwargs):
        self.description = commonmark(self.content)
        return super().save(*args, **kwargs) 
開發者ID:tejoesperanto,項目名稱:pasportaservo,代碼行數:5,代碼來源:models.py

示例3: save

# 需要導入模塊: import commonmark [as 別名]
# 或者: from commonmark import commonmark [as 別名]
def save(self, *args, **kwargs):
        content = re.split(r'(?<!-)----(?!-)', self.content, maxsplit=1)
        self.body = commonmark("".join(content))
        self.description = commonmark(content[0])
        return super().save(*args, **kwargs) 
開發者ID:tejoesperanto,項目名稱:pasportaservo,代碼行數:7,代碼來源:models.py

示例4: rendered_content

# 需要導入模塊: import commonmark [as 別名]
# 或者: from commonmark import commonmark [as 別名]
def rendered_content(self) -> str:
        """Returns the rendered version of raw_content, or just raw_content."""
        from federation.utils.django import get_configuration
        try:
            config = get_configuration()
            if config["tags_path"]:
                def linkifier(tag: str) -> str:
                    return f'<a href="{config["base_url"]}{config["tags_path"].replace(":tag:", tag.lower())}" ' \
                           f'class="mention hashtag" rel="noopener noreferrer">' \
                           f'#<span>{tag}</span></a>'
            else:
                linkifier = None
        except ImportError:
            linkifier = None

        if self._rendered_content:
            return self._rendered_content
        elif self._media_type == "text/markdown" and self.raw_content:
            # Do tags
            _tags, rendered = find_tags(self.raw_content, replacer=linkifier)
            # Render markdown to HTML
            rendered = commonmark(rendered).strip()
            # Do mentions
            if self._mentions:
                for mention in self._mentions:
                    # Only linkify mentions that are URL's
                    if not mention.startswith("http"):
                        continue
                    display_name = get_name_for_profile(mention)
                    if not display_name:
                        display_name = mention
                    rendered = rendered.replace(
                        "@{%s}" % mention,
                        f'@<a href="{mention}" class="mention"><span>{display_name}</span></a>',
                    )
            # Finally linkify remaining URL's that are not links
            rendered = process_text_links(rendered)
            return rendered
        return self.raw_content 
開發者ID:jaywink,項目名稱:federation,代碼行數:41,代碼來源:mixins.py

示例5: read_content

# 需要導入模塊: import commonmark [as 別名]
# 或者: from commonmark import commonmark [as 別名]
def read_content(filename):
    """Read content and metadata from file into a dictionary."""
    # Read file content.
    text = fread(filename)

    # Read metadata and save it in a dictionary.
    date_slug = os.path.basename(filename).split('.')[0]
    match = re.search(r'^(?:(\d\d\d\d-\d\d-\d\d)-)?(.+)$', date_slug)
    content = {
        'date': match.group(1) or '1970-01-01',
        'slug': match.group(2),
    }

    # Read headers.
    end = 0
    for key, val, end in read_headers(text):
        content[key] = val

    # Separate content from headers.
    text = text[end:]

    # Convert Markdown content to HTML.
    if filename.endswith(('.md', '.mkd', '.mkdn', '.mdown', '.markdown')):
        try:
            if _test == 'ImportError':
                raise ImportError('Error forced by test')
            import commonmark
            text = commonmark.commonmark(text)
        except ImportError as e:
            log('WARNING: Cannot render Markdown in {}: {}', filename, str(e))

    # Update the dictionary with content and RFC 2822 date.
    content.update({
        'content': text,
        'rfc_2822_date': rfc_2822_format(content['date'])
    })

    return content 
開發者ID:sunainapai,項目名稱:makesite,代碼行數:40,代碼來源:makesite.py


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