本文整理汇总了Python中markdown.markdown函数的典型用法代码示例。如果您正苦于以下问题:Python markdown函数的具体用法?Python markdown怎么用?Python markdown使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了markdown函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: on_changed_body
def on_changed_body(target, value, oldvalue, initiator):
allowed_tags = ['a', 'abbr', 'b', 'blockquote', 'code', 'em', 'i', 'li', 'ol',
'ul', 'pre', 'strong', 'h1', 'h2', 'h3', 'p']
target.body_html = bleach.linkify(bleach.clean(markdown(value, output_format='html'),
tags=allowed_tags, strip=True))
target.body_abstract = bleach.linkify(bleach.clean(markdown(value, output_format='html'),
tags=['p'], strip=True))
示例2: post
def post(self):
key = self.get_argument("key", None)
if key:
entry = Entry.get(key)
entry.title = self.get_argument("title")
entry.body = self.get_argument("markdown")
entry.markdown = markdown.markdown(self.get_argument("markdown"))
else:
title = self.get_argument("title")
slug = unicodedata.normalize("NFKD", title).encode(
"ascii", "ignore")
slug = re.sub(r"[^\w]+", " ", slug)
slug = "-".join(slug.lower().strip().split())
if not slug: slug = "entry"
while True:
existing = db.Query(Entry).filter("slug =", slug).get()
if not existing or str(existing.key()) == key:
break
slug += "-2"
entry = Entry(
author=self.current_user,
title=title,
slug=slug,
body=self.get_argument("markdown"),
markdown=markdown.markdown(self.get_argument("markdown")),
)
entry.put()
self.redirect("/entry/" + entry.slug)
示例3: add
def add(title, content, c_name, c_id, tags):
summary = content[0:80] + '...'
html = markdown.markdown(content)
diary = {
"_id": Kid.kid(),
"title": title,
"category": c_name,
"category_id": int(c_id),
"tags": tags,
"content": content,
"html": html,
"summary": markdown.markdown(summary),
"publish_time": datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
}
db.diaries.save(diary)
# save category
Category.update_diary(c_id, diary.get('_id'), title, diary.get('publish_time'))
if tags is not None:
# save tags
for tag in tags:
Tag.add(tag, diary)
return
示例4: write_issues
def write_issues(response):
"output a list of issues to csv"
if not r.status_code == 200:
raise Exception(r.status_code)
for issue in r.json():
labels = issue['labels']
for label in labels:
# Control to get only the issue, not the issue comments comments
if IMPORTCHILDS:
# Retrive Parent Issues
if not issue['number'] in issues:
print 'Issue: ' + str(issue['number'])
issues.append(issue['number'])
# Convert Markdown to HTML
try:
html = markdown(issue['body'].encode('utf-8'))
except UnicodeDecodeError:
html = issue['body'].encode('utf-8')
print("Oops! That was no valid char. Saved without format ...")
csvout.writerow([issue['number'], issue['title'].encode('utf-8'), html, 'New', issue['created_at'] ])
# TO DO: here we have the childs, we could insert in another CSV
else:
print 'Issue Child'
else:
try:
html = markdown(issue['body'].encode('utf-8'))
except UnicodeDecodeError:
html = issue['body'].encode('utf-8')
print("Oops! That was no valid char. Saved without format ...")
csvout.writerow([issue['number'], issue['title'].encode('utf-8'), issue['body'].encode('utf-8'), 'New', issue['created_at']])
示例5: make_page
def make_page(filename):
calling_dir = os.getcwd()
with codecs.open(filename, encoding='utf-8') as f:
lines = [line for line in f]
title_line = lines.pop(0)
header = markdown.markdown(title_line)
title = title_to_text(title_line)
lines = add_code_blocks(lines)
slides = slides_from(lines)
if slides:
slides = '<div>\n' + title + '\n</div>\n' + slides
slides_start = file_or_bust(calling_dir, 'slides_header.html')
slides_end = file_or_bust(calling_dir, 'slides_footer.html')
slides_html = slides_start + slides + slides_end
else:
slides_html = None
regex = re.compile(r'([0-9]{4})(?:.?)([0-9]{2})(?:.?)([0-9]{2})')
match = regex.search(calling_dir)
if match:
date_string = ''.join(match.groups())
date = datetime.strptime(date_string, '%Y%m%d')
date_string = datetime.strftime(date, '%A %B %e, %Y')
header += '\n<p class="date">' + date_string + '</p>\n'
body = markdown.markdown("".join(lines))
start = file_or_bust(calling_dir, 'header.html')
start = start.replace('HEAD_TITLE', title)
end = file_or_bust(calling_dir, 'footer.html')
if slides:
slides_loader = file_or_bust(calling_dir, 'slides_loader.html')
body = body + slides_loader
plain_html = start + header + body + end
return plain_html, slides_html
示例6: build_items
def build_items(self):
''' Perform the markdown and jinja2 steps on the raw Items and write to files '''
def write_out(self,item):
"""Make the item into a jinja template, render it and write the output"""
template = self.jinja_env.from_string(item.content)
item.rendered = template.render(page=item, site=self.site)
print ("Creating: " + item.tpath + "/" + item.name + ".html")
f = open(item.tpath + "/" + item.name + ".html", "w")
f.write(item.rendered)
f.close()
for item in self.posts:
# posts are considered to be all in the block called 'content'
tt = copy.deepcopy(item)
if item.ext == ".md" or item.ext == ".markdown":
item.content = markdown.markdown(item.raw, extensions=['markdown.extensions.extra']) # This means we have the converted posts for all our pages should we need it (like the index page that might show a complete post)
# Since this is markdown, we cant add an extends statement so we set the whole thing as a content block
tt.content = markdown.markdown(tt.raw, extensions=['markdown.extensions.extra'])
tt.content = "{% block content %}\n" + tt.content + "{% endblock %}"
tt.content = "{{% extends '{0}' %}}\n".format(item.metadata["layout"]) + tt.content
write_out(self,tt)
for item in self.pages:
tt = copy.deepcopy(item)
tt.content = "{{% extends '{0}' %}}\n".format(item.metadata["layout"]) + tt.content
write_out(self,tt)
示例7: theater
def theater():
""" Serves the theater view from the index URL """
# Store scene list on global object
g.standard_scenes = STANDARD_SCENES
# Render markdown from about ('home.md') file and store on global object
with open(os.path.join(PATHS['home'], 'home.md')) as home_file:
g.home = Markup(markdown(home_file.read()))
# Load project index data structure into global object
with open(os.path.join(PATHS['projects'],'project_index.json')) as index_file:
g.project_index = json.load(index_file)['project_index']
# Create scenes dict on global object and populate with standard scenes...
g.scenes = {}
for scene in g.standard_scenes:
g.scenes[scene] = Markup(render_template(scene + '.html'))
# ...and project scenes
for filename in os.listdir(PATHS['projects']):
if filename.endswith('.md'):
with open(os.path.join(PATHS['projects'], filename)) as project_file:
g.scenes[filename.replace('.md', '')] = Markup(markdown(project_file.read()))
# Render page
return render_template('theater.html')
示例8: save
def save(self, force_insert = False, force_update = False):
if not self.id:
self.pub_date = datetime.datetime.now()
self.updated_date = datetime.datetime.now()
self.excerpt_html = markdown(self.excerpt)
self.body_html = markdown(self.body)
super(Entry, self).save(force_insert, force_update)
示例9: mkdown
def mkdown(target, source, env):
base = ''
sourcename = str(source[0])
sourcedirname = os.path.dirname(sourcename)
while sourcedirname != '':
base = '../' + base
sourcedirname = os.path.dirname(sourcedirname)
mkstr = source[0].get_text_contents()
titlere = re.compile(r"^\s*#\s*([^\n]*)(.*)", re.DOTALL)
title = titlere.findall(mkstr)
if len(title) == 0:
title = "Deft"
else:
mkstr = title[0][1]
title = mmdd.markdown(title[0][0])
title = title[3:len(title)-4]
mkstr = string.Template(mkstr).safe_substitute(base = base)
sidebar = string.Template(source[1].get_text_contents()).safe_substitute(base = base)
template = string.Template(source[2].get_text_contents())
htmlfile = str(target[0])
f = open(str(target[0]), 'w')
f.write(template.safe_substitute(base = base,
title = title,
content = mmdd.markdown(mkstr, extensions=['mathjax']),
sidebar = mmdd.markdown(sidebar, extensions=['mathjax'])))
f.close()
示例10: save
def save(self, *args, **kwargs):
if self.id:
self.Create_Draft()
if not self.body:
self.body = 'No text entered.'
self.body_html = 'No text entered.'
if not self.guid:
#GUID Generation
guid_base = "%s-%s-%s" % (self.user, self.pub_date, self.title)
guid_encoded = guid_base.encode('ascii', 'ignore')
guid = md5(guid_encoded).hexdigest()[:16]
self.guid = guid
if not self.pub_date:
self.pub_date = datetime.datetime.now
if self.content_format == u'markdown':
self.deck_html = markdown.markdown(smart_unicode(self.deck))
self.body_html = markdown.markdown(smart_unicode(self.body))
else:
self.body_html = self.body
self.deck_html = self.deck
if not self.title:
self.title = guid
self.slug = slugify(guid)
self.slug = slugify(self.title)
super(Entry, self).save(*args, **kwargs)
示例11: gener_docs_header
def gener_docs_header(self, branch, one_page):
header = """
<div id="headwrap" class="columnlist">
<div id="headl" class="column">{0}</div>
<div id="headr" class="column">{1}</div>
</div>
"""
lheader = """
### [Home](/) -> [Documentation][{ot}]
[one_page]: /doc/user_guide.html
[mul_page]: /doc/mpage/index.html """
rheader = """
### [{type}][{t}]
[one_page]: /doc/user_guide.html
[mul_page]: /doc/mpage/index.html """
env = {
'type' : 'Page Per Chapter' if one_page else 'All in One Page',
'ot' : 'one_page' if one_page else 'mul_page',
't' : 'mul_page' if one_page else 'one_page',
}
lheader = markdown(lheader.format(**env), extensions=mdext)
rheader = markdown(rheader.format(**env), extensions=mdext)
return header.format(lheader, rheader)
示例12: content
def content(self):
page = self.get_page(self.request.matchdict['uuid'])
if not page:
raise HTTPNotFound()
if page.linked_pages:
linked_pages = to_eg_objects(self.workspace.S(Page).filter(
uuid__in=page.linked_pages))
else:
linked_pages = []
category = None
if page.primary_category:
category = self.get_category(page.primary_category)
if page.language != self.locale:
raise HTTPNotFound()
context = {
'page': page,
'linked_pages': linked_pages,
'primary_category': category,
'content': markdown(page.content),
'description': markdown(page.description),
}
context.update(self.get_comment_context(page))
return context
示例13: project
def project(request, project_name):
project = Project.objects.get(short_name=project_name)
related_projects = Project.objects.filter(related=project.id)
press_links = Press.objects.filter(projects=project.id)
media_links = Media.objects.filter(projects=project.id)
photo_links = Photo.objects.filter(project=project.id)
content_body = None
article_path = os.path.join(settings.PORTFOLIO_CONTENT_PATH, str(project.short_name), 'articles')
desc_file = os.path.join(article_path, 'description.markdown')
if os.path.isfile(desc_file):
with open(desc_file, "r") as f:
content_body = markdown.markdown(f.read())
articles = []
for (root, dirs, files) in os.walk(article_path):
for f in files:
if os.path.splitext(f)[-1] == ".markdown":
# parse the article name from the filename
filename = os.path.split(f)[-1]
urlname = " ".join(os.path.splitext(filename)[0].split("-")) #" ".join("-".split(os.path.splitext(filename)[0]))
urltitle = string.capwords(urlname)
articles.append({"name": urltitle,"filepath": "/".join([project.short_name,"articles",os.path.splitext(filename)[0]])})
description = project.description
if project.description_long is not None:
description = markdown.markdown(project.description_long)
photo_thumbnails = {}
for photo in photo_links:
if photo.flickr_url is not None:
photo.photo_url = photo.flickr_url
photo.thumbnail_url = re.sub(r'.jpg', r'_t.jpg', photo.flickr_url)
return render_to_response('portfolio/project.djhtml', {"project" : project, "desc": description, "press_links": press_links, "media_links": media_links, "photo_links": photo_links, "photo_thumbnails": photo_thumbnails, "related_projects": related_projects, "articles": articles, "content_body": content_body })
示例14: save
def save(self, **kwargs):
new_revision = not self.id
silent_update = kwargs.has_key('silent_update')
if silent_update:
kwargs.pop('silent_update')
if new_revision and self.pub_date is None:
self.pub_date = datetime.datetime.now()
if not silent_update:
self.updated_date = datetime.datetime.now()
# Use safe_mode in Markdown to prevent arbitrary input
# and strip all html tags from CharFields
self.version = strip_tags(self.version)
self.authors = strip_tags(self.authors)
self.changes_html = markdown(self.changes, safe_mode=True)
self.description_html = markdown(self.description, safe_mode=True)
self.tags = strip_tags(self.tags)
self.language = strip_tags(self.language)
self.os_license = strip_tags(self.os_license)
self.paper_bib = strip_tags(self.paper_bib)
self.operating_systems = strip_tags(self.operating_systems)
self.dataformats = strip_tags(self.dataformats)
super(Revision, self).save(kwargs)
# Update authorlist, taglist, licenselist, langaugelist, opsyslist
self.update_list('authorlist','Author','authors')
self.update_list('taglist','Tag','tags')
self.update_list('licenselist','License','os_license')
self.update_list('languagelist','Language','language')
self.update_list('opsyslist','OpSys','operating_systems')
self.update_list('dataformatlist','DataFormat','dataformats')
# send out notifications on updates
if not silent_update:
self.software.notify_update()
示例15: convert_one
def convert_one(part, config, charset):
text = part.get_payload(decode=True)
if part.get_charset():
charset = get_charset_from_message_fragment(part)
if not isinstance(text, six.text_type):
# decode=True only decodes the base64/uuencoded nature, and
# will always return bytes; gotta decode it
if charset is not None:
text = text.decode(charset)
else:
try:
text = text.decode('ascii')
except UnicodeError:
# this is because of message.py:278 and seems like a hack
text = text.decode('raw-unicode-escape')
if not text.startswith('!m'):
return None
text = re.sub(r'\s*!m\s*', '', text, re.M)
if '\n-- \n' in text:
pre_signature, signature = text.split('\n-- \n')
md = markdown.markdown(pre_signature, output_format="html5")
md += '\n<div class="signature" style="font-size: small"><p>-- <br />'
md += '<br />'.join(signature.split('\n'))
md += '</p></div>'
else:
md = markdown.markdown(text)
if config.css:
md = '<style>' + config.css + '</style>' + md
md = pynliner.fromString(md)
message = MIMEText(md, 'html', _charset="UTF-8")
return message