从文件和字符串中提取yaml frontmatter。
frontmatter的Python项目详细描述
前题
一个简单的python包,用于从文本文件或字符串解析yaml frontmatter。为Python3编写,但也应适用于Python2.7。
用法
from frontmatter import Frontmatter
# assuming 'testfile.md' exists
post = Frontmatter.read_file('testfile.md')
print(post['attributes'], "\n") # Dictionary
print(post['body'], "\n") # String
print(post['frontmatter']) # String
输出为:
{'foo': 'bar', 'num': 3, 'list': ['first', 'second', 'third']}
This is the actual post content
This is a second line
foo: bar
num: 3
list:
- first
- second
- third
在上面的示例中,testfile.md的内容是:
---
foo: bar
num: 3
list:
- first
- second
- third
---
This is the actual post content
This is a second line
许可证
版权所有(c)2018,Jonathan Beebe
允许任何人使用、复制、修改和/或分发本软件 特此授予收费或不收费的目的,前提是 版权声明和本许可声明出现在所有副本中。
软件按“原样”提供,作者不作任何保证 关于本软件,包括 适销性和适用性。在任何情况下,作者都不承担责任 任何特殊的、直接的、间接的或间接的损害或任何损害 任何由于使用、数据或利润损失而导致的,无论是 因下列原因引起的合同诉讼、疏忽或其他侵权诉讼 或与本软件的使用或性能有关。