convert()
需要文本。更换
md.convert(file)
通过
md.convert(open(file).read())
。
import markdown as m
print "Markdown version: ", m.version
file = "file.md"
md = m.Markdown(extensions=['meta']) # doesn't complain
print "Registered extensions: ", md.registeredExtensions
print "Preprocessors:", md.preprocessors.keys()
text = open(file).read()
try:
print md.convert(text)
except AttributeError as a:
print "Error: ", a
print "Meta: ", md.Meta
输出:
Markdown version: 2.1.0
Registered extensions: []
Preprocessors: ['meta', 'html_block', 'reference']
<p>Simple md test
<img alt="Chaleur" src="../content/chaleur.jpg" /></p>
Meta: {u'date': [u'2010-07-11'], u'author': [u'Gui13'], u'title': [u'Chaleur']}