【发布时间】:2021-05-31 22:22:54
【问题描述】:
我正在尝试使用python-markdown 从以下文件中提取元数据:
---
title: this is the title and it is compulsory
tags: this part is optional
something: this is not interesting, only 'title' and 'tags' is
---
some content
元数据的documentation 给出了两个示例:
markdown.markdown(some_text, extensions=['meta'])
和
>>> md = markdown.Markdown(extensions = ['meta'])
>>> html = md.convert(text)
>>> # Meta-data has been stripped from output
>>> print html
<p>This is the first paragraph of the document.</p>
>>> # View meta-data
>>> print md.Meta
{
'title' : ['My Document'],
'summary' : ['A brief description of my document.'],
'authors' : ['Waylan Limberg', 'John Doe'],
'date' : ['October 2, 2007'],
'blank-value' : [''],
'base_url' : ['http://example.com']
}
我无法从这些示例中了解如何实际获取元数据:
- 第一个示例返回一个
str,当然它没有Meta属性 - 第二个示例不加载
text,除了html(不用于提取元数据)。
【问题讨论】:
标签: python python-3.x markdown