简体   繁体   中英

Create a dictionary from a formatted file

I want to be able to read in a file, post.md , like this:

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:

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. Maybe someone who knows pelican's code base better than myself can figure out how it is done there.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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