本文整理匯總了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)
示例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)
示例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)
示例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
示例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