Manipulate YAML front matter.
Project description
py-frontmatter
To manipulate front matter in document file.
Installation
pip install py-frontmatter
Usage
Given text file:
---
title: Hacker's note
tags: [a, b]
---
# header
text
Get or set whole section of front matter
To retrieve front matter as JSON:
% frontmatter get note.md | jq
{
"title": "Hacker's note",
"tags": [
"a",
"b"
]
}
To replace the front matter:
% echo '{"title": "My note", "tags": ["a", "b", "c"]}' | frontmatter set note.md
% cat note.md
---
title: My note
tags:
- a
- b
- c
---
# header
text
Add or remove item from front matter
% frontmatter add-item --jsonpath '$.tags' --item d note.md
% cat note.md
---
title: My note
tags:
- a
- b
- c
- d
---
# header
text
%
% frontmatter remove-item --jsonpath '$.tags' --item d note.md
% cat note.md
---
title: My note
tags:
- a
- b
- c
---
# header
text
Specialize commands to add/remove tag
% frontmatter add-tag --tag d note.md
% cat note.md
---
title: My note
tags:
- a
- b
- c
- d
---
# header
text
% frontmatter remove-tag --tag d note.md
% cat note.md
---
title: My note
tags:
- a
- b
- c
---
# header
text
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
py_frontmatter-0.3.0.tar.gz
(10.3 kB
view hashes)
Built Distribution
Close
Hashes for py_frontmatter-0.3.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f98e6c168731a3435c811dfc89e204e8b54495db7386174cd19ca38e9eb204a2 |
|
MD5 | 4d97c9dd6973d94a93d3574b11487460 |
|
BLAKE2b-256 | fbd491b5de9ba39cda75acd784a4cbd3c1de6d452977a8da5578a117197e4c0a |