frontmatter
Parse frontmatter from content string.
| CLASS | DESCRIPTION |
|---|---|
Post |
A post contains content and metadata from frontmatter. This is what gets returned by |
| FUNCTION | DESCRIPTION |
|---|---|
dump_frontmatter |
Dump frontmatter metadata and content into a string. |
force_unicode |
Return Unicode text no matter what. |
parse_frontmatter |
Parse frontmatter from content string. |
Classes¶
Post
¶
Post(metadata: dict[str, Any], content: str)
A post contains content and metadata from frontmatter. This is what gets returned by parse_frontmatter.
For convenience, metadata values are available as proxied item lookups.
| METHOD | DESCRIPTION |
|---|---|
__contains__ |
Check metadata contains the key. |
__delitem__ |
Delete a metadata key. |
__getitem__ |
Get metadata key. |
__setitem__ |
Set a metadata key. |
dumps |
Dump the post to a string of Markdown content. |
get |
Get a key, fallback to default. |
keys |
Return metadata keys. |
loads |
Create a Post from a string of Markdown content. |
to_dict |
Post as a dict, for serializing. |
values |
Return metadata values. |
| ATTRIBUTE | DESCRIPTION |
|---|---|
content |
The content of the post.
TYPE:
|
metadata |
The metadata of the post.
TYPE:
|
Functions:¶
dump_frontmatter
¶
dump_frontmatter(metadata: dict[str, Any] | None, content: str) -> str
Dump frontmatter metadata and content into a string.
| PARAMETER | DESCRIPTION |
|---|---|
metadata
|
The frontmatter metadata as a dictionary.
TYPE:
|
content
|
The content string.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
str
|
The combined frontmatter and content string. If metadata is None, only the content is returned. |
force_unicode
¶
force_unicode(text: str | bytes, encoding: str = 'utf-8') -> str
Return Unicode text no matter what.
parse_frontmatter
¶
parse_frontmatter(content: str) -> tuple[dict[str, Any], str]
Parse frontmatter from content string.
| PARAMETER | DESCRIPTION |
|---|---|
content
|
The file content as a string
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
tuple[dict[str, Any], str]
|
Tuple of (frontmatter_dict, remaining_content) |
| RAISES | DESCRIPTION |
|---|---|
ValueError
|
If the frontmatter is invalid YAML |