本文整理汇总了Python中markdown.Markdown.Meta方法的典型用法代码示例。如果您正苦于以下问题:Python Markdown.Meta方法的具体用法?Python Markdown.Meta怎么用?Python Markdown.Meta使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类markdown.Markdown
的用法示例。
在下文中一共展示了Markdown.Meta方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: convert
# 需要导入模块: from markdown import Markdown [as 别名]
# 或者: from markdown.Markdown import Meta [as 别名]
def convert(self, source, **context):
""" Converts the source file and saves to the destination """
with codecs.open(source, encoding='utf-8') as src:
lines = src.readlines()
# Parse metadata first so we can get theme extensions
md = Markdown()
lines = MetaPreprocessor(md).run(lines)
Meta = md.Meta
meta = {k: ' '.join(v) for k, v in Meta.items()}
# Load theme from meta data if set
theme = meta.get('theme', 'default')
exts = self.config.theme_get(theme, 'markdown_extensions', [
'codehilite(css_class=syntax,guess_lang=False)'])
exts = filter(None, exts) # Removes empty lines
md = Markdown(extensions=exts)
md.Meta = meta # restore already parsed meta data
content = md.convert(''.join(lines))
context['Meta'] = Meta
context['meta'] = meta
return self.config.render_template(theme, content, **context)
示例2: __init__
# 需要导入模块: from markdown import Markdown [as 别名]
# 或者: from markdown.Markdown import Meta [as 别名]
def __init__(self, request, path, parent=None):
super(BlogEntry, self).__init__(request, path, parent=parent)
self.base_name, self.ext = os.path.splitext(path)
assert self.ext.lower() in self.EXT, " %s is not a markdown file" % path
m = Markdown(extensions=md_extensions)
m.Meta = {}
body = cStringIO.StringIO()
m.convertFile(input=open(self.path), output=body)
self.body = body.getvalue()
body.close()
for k, v in m.Meta.items():
setattr(self, k, " ".join(v))
self.page = BlogPage(request, "%s.html" % self.base_name, self)
示例3: read_markdown
# 需要导入模块: from markdown import Markdown [as 别名]
# 或者: from markdown.Markdown import Meta [as 别名]
def read_markdown(filename):
"""Reads markdown file, converts output and fetches title and meta-data for
further processing.
"""
global MD
# Use utf-8-sig codec to remove BOM if it is present. This is only possible
# this way prior to feeding the text to the markdown parser (which would
# also default to pure utf-8)
with open(filename, 'r', encoding='utf-8-sig') as f:
text = f.read()
if MD is None:
MD = Markdown(extensions=['markdown.extensions.meta',
'markdown.extensions.tables'],
output_format='html5')
else:
MD.reset()
# When https://github.com/Python-Markdown/markdown/pull/672
# will be available, this can be removed.
MD.Meta = {}
# Mark HTML with Markup to prevent jinja2 autoescaping
output = {'description': Markup(MD.convert(text))}
try:
meta = MD.Meta.copy()
except AttributeError:
pass
else:
output['meta'] = meta
try:
output['title'] = MD.Meta['title'][0]
except KeyError:
pass
return output