本文整理汇总了Python中mistune.markdown方法的典型用法代码示例。如果您正苦于以下问题:Python mistune.markdown方法的具体用法?Python mistune.markdown怎么用?Python mistune.markdown使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mistune
的用法示例。
在下文中一共展示了mistune.markdown方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: render_content
# 需要导入模块: import mistune [as 别名]
# 或者: from mistune import markdown [as 别名]
def render_content(content_raw, sender):
"""
:param content_raw: Raw content
:param sender: user as username
:return: (rendered_content, mentioned_user_list)
"""
content_rendered = mistune.markdown(content_raw)
mentioned = list(set(re.findall(MENTION_REGEX, content_raw)))
mentioned = [x for x in mentioned if x != sender]
mentioned_users = get_user_model().objects.filter(username__in=mentioned)
for user in mentioned_users:
content_rendered = re.sub(
r'(?P<username>@%s)(?P<whitespace>\s|<\/p>)' % user.username,
partial(_replace_username, reverse('niji:user_info', kwargs={"pk": user.pk})),
content_rendered,
re.M
)
return content_rendered, mentioned_users
示例2: parse
# 需要导入模块: import mistune [as 别名]
# 或者: from mistune import markdown [as 别名]
def parse(post_path):
"""Parses the metadata and content from the provided post.
Arguments:
post_path {str} -- The absolute path to the Markdown post
"""
raw_yaml = ''
markdown = ''
in_yaml = True
with open(post_path, 'r') as post:
for line in post.readlines():
# Check if this is the ending tag
if line.strip() == YAML_BOUNDARY:
if in_yaml and raw_yaml:
in_yaml = False
continue
if in_yaml:
raw_yaml += line
else:
markdown += line
front_matter = yaml.load(raw_yaml, Loader=yaml.SafeLoader)
markdown = markdown.strip()
return front_matter, markdown
示例3: _create_jinja_environment
# 需要导入模块: import mistune [as 别名]
# 或者: from mistune import markdown [as 别名]
def _create_jinja_environment(runfiles, site_root, link_ext):
def _Load(path):
loc = runfiles.Rlocation(posixpath.join(WORKSPACE_DIR, TEMPLATE_PATH, path))
if loc:
with open(loc, "rb") as f:
return f.read().decode("utf-8")
return None
env = jinja2.Environment(
loader=jinja2.FunctionLoader(_Load),
keep_trailing_newline=True,
line_statement_prefix='%')
env.filters['markdown'] = lambda text: jinja2.Markup(mistune.markdown(text))
env.filters['doc_link'] = (
lambda fname: site_root + '/' + fname + '.' + link_ext)
env.filters['link'] = lambda fname: site_root + '/' + fname
return env
# TODO(dzc): Remove this workaround once we switch to a self-contained Python
# binary format such as PEX.
示例4: compose_email_body
# 需要导入模块: import mistune [as 别名]
# 或者: from mistune import markdown [as 别名]
def compose_email_body(articles, keywords, feed_list):
'''
From the list of articles, keywords and feeds, fill the email template
Set the list in the adequate format for the template
'''
# Compose the list of articles
ARTICLE_TEMPLATE = '* **{title}** {summary}: {link}'
article_list = [ARTICLE_TEMPLATE.format(title=title, summary=summary,
link=link)
for title, summary, link in articles]
data = {
'article_list': '\n'.join(article_list),
'keywords': ', '.join(keywords),
'feed_list': ', '.join(feed_list),
}
text = EMAIL_TEMPLATE.format(**data)
html_content = mistune.markdown(text)
html = jinja2.Template(EMAIL_STYLING).render(content=html_content)
return text, html
示例5: load_fixtures
# 需要导入模块: import mistune [as 别名]
# 或者: from mistune import markdown [as 别名]
def load_fixtures(cls, case_file):
cases = fixtures.load_json(case_file)
def attach_case(n, data):
def method(self):
tokens = mistune.markdown(data['text'], renderer='ast')
self.assertEqual(tokens, data['tokens'])
name = 'test_{}'.format(n)
method.__name__ = name
method.__doc__ = 'Run fixture {} - {}'.format(case_file, n)
setattr(cls, name, method)
for n, data in enumerate(cases):
attach_case(n, data)
示例6: write_entry
# 需要导入模块: import mistune [as 别名]
# 或者: from mistune import markdown [as 别名]
def write_entry(filename):
'''
entry text generator
* dump given file into entry format by parsing file as markdown
* return as list of strings
'''
date = util.parse_date(filename)
entry = [
"\t\t<p><a name=\""+date[0]+date[1]+date[2]+"\"></a><br /><br /></p>\n",
"\t\t<div class=\"entry\">\n",
"\t\t\t<h5><a href=\"#"+date[0]+date[1]+date[2]+"\">"+date[2]+"</a> "+chatter.month(date[1])+" "+date[0]+"</h5>\n"
#"\t\t\t<P>"
]
raw = []
rawfile = open(os.path.join(config.MAIN_FEELS, filename), "r")
for line in rawfile:
raw.append(line)
rawfile.close()
entry.append("\t\t\t"+mistune.markdown("".join(raw), escape=False, hard_wrap=False))
#for line in raw:
#entry.append(line+"\t\t\t")
#if line == "\n":
# entry.append("</p>\n\t\t\t<p>")
#entry.append("</p>\n")
entry.append("\t\t\t<p class=\"permalink\"><a href=\""+"".join(date)+".html\">permalink</a></p>\n")
entry.append("\n\t\t</div>\n")
return entry
示例7: update_profile_data
# 需要导入模块: import mistune [as 别名]
# 或者: from mistune import markdown [as 别名]
def update_profile_data(self):
self.about_html = mistune.markdown(self.about_text)
if self.display_picture:
self.gravatar_hash = md5(self.email.lower().encode('utf-8')).hexdigest()
示例8: generate_html
# 需要导入模块: import mistune [as 别名]
# 或者: from mistune import markdown [as 别名]
def generate_html(self):
if self.text:
html = mistune.markdown(self.text)
self.text_html = html
示例9: create
# 需要导入模块: import mistune [as 别名]
# 或者: from mistune import markdown [as 别名]
def create(cls, author, raw_comment, parent):
"""
Create a new comment instance. If the parent is submisison
update comment_count field and save it.
If parent is comment post it as child comment
:param author: RedditUser instance
:type author: RedditUser
:param raw_comment: Raw comment text
:type raw_comment: str
:param parent: Comment or Submission that this comment is child of
:type parent: Comment | Submission
:return: New Comment instance
:rtype: Comment
"""
html_comment = mistune.markdown(raw_comment)
# todo: any exceptions possible?
comment = cls(author=author,
author_name=author.user.username,
raw_comment=raw_comment,
html_comment=html_comment)
if isinstance(parent, Submission):
submission = parent
comment.submission = submission
elif isinstance(parent, Comment):
submission = parent.submission
comment.submission = submission
comment.parent = parent
else:
return
submission.comment_count += 1
submission.save()
return comment
示例10: save
# 需要导入模块: import mistune [as 别名]
# 或者: from mistune import markdown [as 别名]
def save(self, *args, **kwargs):
new_hash = xxhash.xxh64(self.content_raw).hexdigest()
if new_hash != self.raw_content_hash or (not self.pk):
self.content_rendered = mistune.markdown(self.content_raw)
super(Appendix, self).save(*args, **kwargs)
self.raw_content_hash = new_hash
示例11: convtoconf
# 需要导入模块: import mistune [as 别名]
# 或者: from mistune import markdown [as 别名]
def convtoconf(markdown, front_matter={}):
if front_matter is None:
front_matter = {}
author_keys = front_matter.get('author_keys', [])
renderer = ConfluenceRenderer(authors=author_keys)
content_html = mistune.markdown(markdown, renderer=renderer)
page_html = renderer.layout(content_html)
return page_html, renderer.attachments
示例12: prepare
# 需要导入模块: import mistune [as 别名]
# 或者: from mistune import markdown [as 别名]
def prepare(self):
"""
Prepare the `self.message` object.
"""
if self.prepared_message:
self.message = message_from_bytes(self.prepared_message)
self.prepared = True
return
self.text = self.text or BeautifulSoup(self.html, 'html.parser').get_text(strip=True)
self.html = self.html or mistune.markdown(self.text)
self.message['Sender'] = stringify_address(self.sender)
self.message['From'] = stringify_addresses(self.authors) if self.authors else stringify_address(self.sender)
self.message['To'] = stringify_addresses(self.receivers)
self.message['Subject'] = self.subject
if self.cc:
self.message['CC'] = stringify_addresses(self.cc)
if self.bcc:
self.message['BCC'] = stringify_addresses(self.bcc)
if self.reply_to:
self.message['Reply-To'] = stringify_addresses(self.reply_to)
if self.headers:
for key, value in self.headers.items():
self.message[key] = value
body = MIMEMultipart('alternative')
plaintext_part = MIMEText(self.text, 'plain')
html_part = MIMEText(self.html, 'html')
body.attach(plaintext_part)
body.attach(html_part)
self.message.attach(body)
self.prepared = True
示例13: parse_adr_to_config
# 需要导入模块: import mistune [as 别名]
# 或者: from mistune import markdown [as 别名]
def parse_adr_to_config(path):
adr_as_html = mistune.markdown(open(path).read())
soup = BeautifulSoup(adr_as_html, features='html.parser')
status = list(extract_statuses_from_adr(soup))
if any([line.startswith("Amended by") for line in status]):
status = 'amended'
elif any([line.startswith("Accepted") for line in status]):
status = 'accepted'
elif any([line.startswith("Superceded by") for line in status]):
status = 'superceded'
elif any([line.startswith("Pending") for line in status]):
status = 'pending'
else:
status = 'unknown'
header = soup.find('h1')
if header:
return {
'status': status,
'body': adr_as_html,
'title': header.text
}
else:
return None
示例14: _write_ruleset
# 需要导入模块: import mistune [as 别名]
# 或者: from mistune import markdown [as 别名]
def _write_ruleset(self, output_dir, ruleset):
# Load template and render Markdown.
template = self.__env.get_template('markdown.jinja')
out = template.render(ruleset=ruleset)
# Write output to file. Output files are created in a directory structure
# that matches that of the input file.
output_path = ruleset.output_file + '.md'
output_file = "%s/%s" % (output_dir, output_path)
file_dirname = os.path.dirname(output_file)
if not os.path.exists(file_dirname):
os.makedirs(file_dirname)
with open(output_file, "w") as f:
f.write(out)
return (output_file, output_path)
示例15: save
# 需要导入模块: import mistune [as 别名]
# 或者: from mistune import markdown [as 别名]
def save(self, *args, **kwargs):
self.content = mistune.markdown(self.content_raw)
super(Post, self).save(*args, **kwargs)