简体   繁体   English

从格式化文件创建字典

[英]Create a dictionary from a formatted file

I want to be able to read in a file, post.md , like this: 我希望能够像这样读取文件post.md

title: Some Title
slug: some-title
author: Joe Smith
date: Jan 23 2015
tags: a, b, c, d

This is the first paragraph of the post.

This is another paragraph.

and generate a python dictionary like this: 并生成这样的python字典:

post = {
    "title": "Some Title",
    "slug": "some-title",
    "author": "Joe Smith",
    "title": datetime.date(2015, 1, 23),
    "tags": ["a", "b", "c", "d",],
    "body": "This is the first paragraph of the post.\n\nThis is another paragraph."
}

It is acceptable to modify the file input slightly, but can't go full yaml because I want markdown highlighting. 可以略微修改文件输入是可以接受的,但是由于我想要Markdown高亮显示,所以不能完全使用Yaml。 Maybe someone who knows pelican's code base better than myself can figure out how it is done there. 也许比我自己更了解鹈鹕代码库的人可以弄清楚那里是如何实现的。

如@Carl Groner所建议的,这可以通过Python Markdown元数据扩展来完成。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM