本文整理汇总了Python中markdown.markdown函数的典型用法代码示例。如果您正苦于以下问题:Python markdown函数的具体用法?Python markdown怎么用?Python markdown使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了markdown函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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))
开发者ID:yelongyu,项目名称:chihu,代码行数:7,代码来源:models.py
示例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)
开发者ID:ThrowDice,项目名称:blog,代码行数:28,代码来源:blog.py
示例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
开发者ID:Daniel7725,项目名称:Dev_Blog,代码行数:25,代码来源:diaries.py
示例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']])
开发者ID:Pirata21,项目名称:github-issues-to-salesforce,代码行数:32,代码来源:importer.py
示例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
开发者ID:EricSchles,项目名称:ajschumacher.github.io,代码行数:32,代码来源:make_page.py
示例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)
开发者ID:OniDaito,项目名称:Tachikoma,代码行数:28,代码来源:tachikoma.py
示例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')
开发者ID:boothandrewd,项目名称:flask_website,代码行数:25,代码来源:andrewdbooth.py
示例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)
开发者ID:gotoc,项目名称:basic_django,代码行数:7,代码来源:models.py
示例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()
开发者ID:maksimovica,项目名称:deft,代码行数:28,代码来源:__init__.py
示例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)
开发者ID:underlost,项目名称:Replica,代码行数:25,代码来源:models.py
示例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)
开发者ID:venkatarajasekhar,项目名称:bee,代码行数:29,代码来源:static.py
示例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
开发者ID:universalcore,项目名称:unicore-cms,代码行数:28,代码来源:cms_views.py
示例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 })
开发者ID:qdot,项目名称:np_portfolio,代码行数:32,代码来源:views.py
示例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()
开发者ID:bairuiworld,项目名称:mloss,代码行数:35,代码来源:models.py
示例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
开发者ID:Roguelazer,项目名称:muttdown,代码行数:31,代码来源:main.py
示例16: get_meta_data
def get_meta_data(filename):
"""Get the meta-data from posts.
"""
log.debug('Parsing meta-data from %s' % filename)
with io.open(filename, 'rt', encoding='utf-8') as f:
content = f.read()
meta = {}
post_match = POST_RE.match(content)
if post_match:
meta = load(post_match.group('meta'), Loader=Loader)
body = post_match.group('body').strip()
if 'layout' in meta:
# The body is pure Markdown without any Jinja syntax
meta['content'] = markdown.markdown(body, ['codehilite'])
meta['raw'] = wrap_jinja2(body, layout=meta['layout'])
else:
# The body contains Jinja syntax
body_without_jinja = strip_jinja2(body)
meta['content'] = markdown.markdown(
body_without_jinja, ['codehilite'])
meta['raw'] = body
else:
meta['raw'] = content.strip()
meta['filename'] = filename
return meta
开发者ID:BoldData,项目名称:voldemort,代码行数:28,代码来源:template.py
示例17: markdown
def markdown(value, arg=''):
extensions = [e for e in arg.split(',') if e]
if extensions and extensions[0] == 'safe':
extensions = extensions[1:]
return mark_safe(mkdn.markdown(force_text(value), extensions, safe_mode=True, enable_attributes=False))
else:
return mark_safe(mkdn.markdown(force_text(value), extensions, safe_mode=False))
开发者ID:agrif,项目名称:osubus,代码行数:7,代码来源:markup.py
示例18: markdown_filter
def markdown_filter(value):
try:
if isinstance(value, unicode):
value = value.decode('utf-8')
return markdown.markdown(value)
except UnicodeEncodeError:
return markdown.markdown(value)
开发者ID:stucox,项目名称:pygrow,代码行数:7,代码来源:builtins.py
示例19: currentItemChanged
def currentItemChanged(self):
item = self.lessonsTree.currentItem()
if item:
if hasattr(item, "lesson"):
self.btnRemove.setText("Uninstall lesson")
self.btnRemove.setEnabled(True)
self.btnRunLesson.setEnabled(True)
if os.path.exists(item.lesson.description):
with codecs.open(item.lesson.description, encoding="utf-8") as f:
html = "".join(f.readlines())
if item.lesson.description.endswith(".md"):
html = markdown.markdown(html)
self.webView.document().setMetaInformation(QTextDocument.DocumentUrl,
QUrl.fromUserInput(item.lesson.description).toString())
self.webView.setHtml(html)
else:
self.webView.setHtml("<p>{}</p>".format(item.lesson.description))
else:
self.btnRunLesson.setEnabled(False)
self.btnRemove.setText("Uninstall lessons group")
self.btnRemove.setEnabled(True)
if os.path.exists(item.description):
with codecs.open(item.description, encoding="utf-8") as f:
html = "".join(f.readlines())
if item.description.endswith(".md"):
html = markdown.markdown(html)
self.webView.document().setMetaInformation(QTextDocument.DocumentUrl,
QUrl.fromUserInput(item.description).toString())
else:
html = item.description
self.webView.setHtml(html)
else:
self.btnRemove.setEnabled(False)
self.btnRunLesson.setEnabled(False)
开发者ID:gioman,项目名称:qgis-lessons-plugin,代码行数:35,代码来源:lessonselector.py
示例20: generate_summary_content
def generate_summary_content(cls, updates):
content = {}
for msg in updates:
for header, text, garbage in msg.parse():
# do some sort of standardizing of case and whitespace to avoid duplicate headers
header = header.strip().title()
if header not in content:
content[header] = {}
# use members_dict.get in case the sender has been removed from the MEMBERS list since
# they sent an email to the list (although this is unlikely).
sender = members_dict.get(msg.sender.lower(), msg.sender)
if sender not in content[header]:
content[header][sender] = {"text": text, "html": markdown(text)}
else:
content[header][sender]["text"] += text
content[header][sender]["html"] += markdown(text)
sorted_content = SortedDict()
def content_key(s):
try:
return int(s.split(".")[0])
except:
return s
for k in sorted(content.keys(), key=content_key):
sorted_content[k] = content[k]
return sorted_content
开发者ID:benbest86,项目名称:watsancomm,代码行数:27,代码来源:models.py
注:本文中的markdown.markdown函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论