本文整理汇总了Python中mistune.markdown函数的典型用法代码示例。如果您正苦于以下问题:Python markdown函数的具体用法?Python markdown怎么用?Python markdown使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了markdown函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: create_issue
def create_issue(self, data, **kwargs):
"""
Creates the issue on the remote service and returns an issue ID.
"""
project_id = data.get('project')
if project_id is None:
raise ValueError('Azure DevOps expects project')
client = self.get_client()
title = data['title']
description = data['description']
try:
created_item = client.create_work_item(
instance=self.instance,
project=project_id,
title=title,
# Decriptions cannot easily be seen. So, a comment will be added as well.
description=markdown(description),
comment=markdown(description)
)
except Exception as e:
self.raise_error(e)
project_name = created_item['fields']['System.AreaPath']
return {
'key': six.text_type(created_item['id']),
'title': title,
'description': description,
'metadata': {
'display_name': '%s#%s' % (project_name, created_item['id']),
}
}
示例2: import_file
def import_file(cls,path=None):
'''
导入博客文件,自动跳过已导入的文件。
'''
path=abspath(path or '~/OneDrive/notes')
note_files=[]
for root,paths,files in os.walk(path):
note_files.extend([join(root,fi) for fi in files
if fi.endswith('.md')])
for fl in cls.find({'filename':{"$in":note_files}},
{'mtime':1,'filename':1}):
if fl['mtime']>=dt_tz(os.path.getmtime(fl['filename'])):
print('文件:%s 已导入,跳过'%(fl['filename']))
note_files.remove(fl['filename'])
renderer=ConvertRenderer()
for filename in note_files:
body='\n'.join(read_file(filename))
renderer.clear()
mistune.markdown(body,renderer=renderer)
cls.update_one({'filename':filename},
{'$set':
{'title':renderer.title,
'abbr':renderer.abbr,
'meta':renderer.meta,
'mtime':dt_tz(os.path.getmtime(filename)),
'ctime':dt_tz(os.path.getctime(filename)),
'body':body}},
True)
示例3: _pre_put_hook
def _pre_put_hook(self):
if not self.original_name:
self.original_name = self.name
self.name = clean_name(self.name)
self.category = strip_string(self.category)
self.badge = strip_string(self.badge)
self.barcode = strip_string(self.barcode)
self.brand = strip_string(self.brand)
self.country = strip_string(self.country)
self.material = strip_string(self.material)
self.description_md = self.description_md.strip()
if self.description_md:
self.description_html = mistune.markdown(self.description_md)
self.description = re.sub(
r'(<!--.*?-->|<[^>]*>)', '', self.description_html)
else:
self.description = self.description.strip()
self.description_md = self.description
self.description_html = mistune.markdown(self.description)
if self.description:
self.short_description = u' '.join(self.description.split()[:5])
else:
self.short_description = ''
self.meta_keywords = self.clear_name.replace(' ', ', ')
示例4: test_parse_block_html
def test_parse_block_html():
ret = mistune.markdown(
'<div>**foo**</div>', parse_block_html=True, escape=False
)
assert '<div><strong>' in ret
ret = mistune.markdown(
'<span>**foo**</span>', parse_block_html=True, escape=False
)
assert '<strong>' not in ret
示例5: add_post_post
def add_post_post():
post = Word(
title = request.form["title"],
content = mistune.markdown(request.form["content"]),
category = mistune.markdown(request.form["category"]),
level = mistune.markdown(request.form["level"]),
author = current_user
)
session.add(post)
session.commit()
return redirect(url_for("words"))
示例6: test_use_xhtml
def test_use_xhtml():
ret = mistune.markdown('foo\n\n----\n\nbar')
assert '<hr>' in ret
ret = mistune.markdown('foo\n\n----\n\nbar', use_xhtml=True)
assert '<hr />' in ret
ret = mistune.markdown('foo \nbar', use_xhtml=True)
assert '<br />' in ret
ret = mistune.markdown('![foo](bar "title")', use_xhtml=True)
assert '<img src="bar" alt="foo" title="title" />' in ret
示例7: __init__
def __init__(self, proto):
self.__proto = proto
self.name = proto.name
self.documentation = mistune.markdown(proto.documentation)
self.example_documentation = mistune.markdown(proto.example_documentation)
self.signature = self._get_signature(proto)
self.attributes = []
for attribute in proto.attribute:
self.attributes.append(Attribute(attribute))
self.outputs = []
for output in proto.output:
self.outputs.append(Output(output))
示例8: _grab_blocks
def _grab_blocks(self):
"""
Parse `self.source` and return a dict mapping block names to their
raw content.
"""
r = BlockRecordRenderer()
mistune.markdown(self.source, renderer=r)
blocks = {}
for block in r.blocks:
name, content = self._parse_raw_block(block)
blocks[name] = content
self.blocks = blocks
示例9: test_parse_nested_html
def test_parse_nested_html():
ret = mistune.markdown(
'<div><a href="http://example.org">**foo**</a></div>',
parse_block_html=True, escape=False
)
assert '<div><a href="http://example.org">' in ret
assert '<strong>' not in ret
ret = mistune.markdown(
'<div><a href="http://example.org">**foo**</a></div>',
parse_block_html=True, parse_inline_html=True, escape=False
)
assert '<div><a href="http://example.org"><strong>' in ret
示例10: test_parse_inline_html
def test_parse_inline_html():
ret = mistune.markdown(
'<div>**foo**</div>', parse_inline_html=True, escape=False
)
assert '<strong>' not in ret
ret = mistune.markdown(
'<span>**foo**</span>', parse_inline_html=True, escape=False
)
assert '<span><strong>' in ret
ret = mistune.markdown(
'<a>http://lepture.com</a>', parse_inline_html=True, escape=False
)
assert 'href' not in ret
示例11: index
def index():
dirs = _get_dirs()
main_index = dict(standard="1377", issue="1990", org="BS", title="BS1377:1990", parts=[])
print dirs
for d in dirs:
files = _get_md_files(d)
print "d=", d
#print "==========", ROOT_PATH + d + "/README.md"
txt = _read_file(ROOT_PATH + d + "/README.md")
html = mistune.markdown(txt)
soup = BeautifulSoup(html)
dic = {}
dic['title'] = str(soup.find("h1").text).strip()
dic['part'] = dic['title'][4:].strip().split(" ")[0].strip()
#dic['sections'] = []
idx = []
for f in files:
#print f
txt = _read_file(ROOT_PATH + f)
html = mistune.markdown(txt)
#print html
soup = BeautifulSoup(html)
print "------------------------------"
title = str(soup.find("h1").text).strip()
toc = []
for h2 in soup.findAll("h2"):
toc.append( dict(title=str(h2.text).strip()) )
#print title, toc
#'toc.append( dict(file=f, title=title, toc=toc) )
#fff = f
#print f, fff
num = f.split("/")[-1][:-3]
print "NO = ", num, type(num)
data = dict(title=title, clauses=toc, file=f, part= str(d)[1:], org="BS", section=num)
idx.append( data )
dic['sections'] = idx
_write_yaml("%s/%s/index.yaml" % (ROOT_PATH, d), dic )
main_index['parts'].append(dic)
#print idx
#break
_write_yaml("%s/index.yaml" % (ROOT_PATH), main_index )
示例12: generate_post
def generate_post(self, text, out_file_name):
html = mistune.markdown(text, escape=False)
result = self.blog_template.format(
content=html, blog_name=self.blog_name)
with open(out_file_name, "w+") as f:
f.write(result)
示例13: get_html
def get_html(self):
if self.text_type == 'rst':
from docutils.core import publish_parts
return publish_parts(self.text, writer_name='html')['html_body']
else:
import mistune
return mistune.markdown(self.text)
示例14: markdownDeck
def markdownDeck(deck):
fl = open("decords/{}".format(deck), "r")
xml = mistune.markdown(fl.read())
fl.close()
del (fl)
xml = etree.fromstring(xml)
pass
示例15: markdownify
def markdownify():
md = request.form.get("markdown")
if md:
html = mistune.markdown(md)
return html
else:
return "no markdown supplied"