本文整理汇总了Python中markdown.Markdown.serializer方法的典型用法代码示例。如果您正苦于以下问题:Python Markdown.serializer方法的具体用法?Python Markdown.serializer怎么用?Python Markdown.serializer使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类markdown.Markdown
的用法示例。
在下文中一共展示了Markdown.serializer方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: md2node
# 需要导入模块: from markdown import Markdown [as 别名]
# 或者: from markdown.Markdown import serializer [as 别名]
def md2node(text):
md = Markdown()
md.serializer = Serializer(md)
md.stripTopLevelTags = False
md.postprocessors = OrderedDict()
md.postprocessors['section'] = SectionPostprocessor()
md.postprocessors['strip'] = StripPostprocessor()
return md.convert(text)
示例2: create_markdown
# 需要导入模块: from markdown import Markdown [as 别名]
# 或者: from markdown.Markdown import serializer [as 别名]
def create_markdown(file_name):
m = Markdown()
output = None
with open(file_name, 'r') as fh:
tree = m.parser.parseDocument(fh.read().split("\n"))
root_node = tree.getroot()
slide_tags = ['h1', 'h2']
# if we find more than 1 h1 tag, we assume that h1 represents a slide.
# if there's only one, the first h1 is probably the title slide.
if len(filter(lambda e: e.tag == 'h1', root_node)) > 1:
slide_tags = ['h1']
new_root = Element('section', attrib={
'id': 'slides'
})
slide_element = None
for node in root_node:
if node.tag in slide_tags:
node.tag = 'h1'
if slide_element is not None:
new_root.append(slide_element)
slide_element = Element('article')
if slide_element is not None:
slide_element.append(node)
if slide_element is not None:
new_root.append(slide_element)
output = m.serializer(new_root)
if output:
output_file_name = file_name.split('/')[-1].split('.')[0] + '.html'
template = None
with open('template.html', 'r') as fh:
template = fh.read()
with open(output_file_name, 'w+') as output_fh:
print "Creating {0}...".format(output_file_name)
output_fh.write(template.format(**{
'body': output
}))
示例3: load
# 需要导入模块: from markdown import Markdown [as 别名]
# 或者: from markdown.Markdown import serializer [as 别名]
def load(self):
path, t = QFileDialog.getOpenFileName()
markdown = Markdown()
markdown.serializer = self._loader
markdown.convertFile(path)