Markup Front Matter Parser
This is an OOP-y Python package for parsing the Front Matter of markup files (e.g. .md, .html).
Front Matter is a YAML snippet at the top of a markup file that stores metadata
that is used commonly in Jekyll static sites.
Note that this package is a simple front matter parser that will only parse single
line key-values. It currently does not support parsing multi-line front matter mapping entries (e.g. YAML lists).
Usage
Install the package with:
pip install markup-front-matter-parser
In your code import the following:
from markup_front_matter_parser import FrontMatterParserFactory, InvalidFrontMatterError
Note: If you'd like to add type-hints to objects, then you can additionally import MarkupFile, MarkupContent, and FileFormat.
To use in your code, start by creating an instance of FrontMatterParserFactory and then call get_parser() with the desired file you want parsed:
parser_factory = FrontMatterParserFactory()
parser: AbstractFrontMatterParser = parser_factory.get_parser("songs/crazy-train.md")
Obtaining the parser may raise a ValueError if the file type is incompatible and a FileNotFoundError if the file is not found.
Calling parse() on this parser instance will return a MarkupFile instance that contains the parsed front matter and other attributes:
try:
markup_file: MarkupFile = parser.parse()
except InvalidFrontMatterException as e:
[...]
For example, parsing the file crazy_train.md:
---
name: Crazy Train
artist: Ozzy Osbourne
---
# This is content.
Hooray for content
Would result in a MarkupFile object composed of:
- A front_matter attribute:
{"name": "Crazy Train", "artist": "Ozzy Osbourne"} - A content attribute (an instance of
MarkupContent[specifically therawattribute]):"# This is content.\nHooray for content\n" - A path attribute:
"crazy_train.md" - A file_format attribute:
FileFormat.MARKDOWN
The parse() method will raise an informative InvalidFrontMatterError if the file's front matter cannot be parsed.
Code Overview
This was written within the context of an in-depth sprint of learning Python, so it may not be the most practical package for the job.
The architecture of the package uses the factory pattern and was designed so that future improvements would not change the public API.
In addition, each subclass of AbstractFrontMatterParser could easily implement their own tokenizing of file-specific markup content.
In this fashion, the package could then become a holistic markup parser rather than solely just a front matter parser.
Metadata
Release files for markup-front-matter-parser 0.6.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| markup_front_matter_parser-0.6.0.tar.gz | 8.8 kB | Without provenance | Details for markup_front_matter_parser-0.6.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| markup_front_matter_parser-0.6.0-py3-none-any.whl | Python 3 | none | any | Details for markup_front_matter_parser-0.6.0-py3-none-any.whl |
Total release size: 18.3 kB
Release files / markup_front_matter_parser-0.6.0.tar.gz
| Download URL | markup_front_matter_parser-0.6.0.tar.gz |
|---|---|
| Size | 8.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
8e5e3d7cc9b1f45d1bef8d92e9af3ff3a2de510cf8eff377eecd6e280dbf553c
|
|
BLAKE2b-256 checksum How to use checksums |
54faf0698cb1255a6f95b987853e0ca795871ab6584e5ae4942bc75a4d973e6b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.12.4
|
Release files / markup_front_matter_parser-0.6.0-py3-none-any.whl
| Download URL | markup_front_matter_parser-0.6.0-py3-none-any.whl |
|---|---|
| Size | 9.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
dbdb1d1114d000bfb42bd90a37f388f809d66987d3ee4f9fbe08de16427198c8
|
|
BLAKE2b-256 checksum How to use checksums |
10cadc7f4fe5cbd67252025c43c33568a4ba4b0e03e9a012c52968b43b2d518a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.12.4
|
Security for markup-front-matter-parser 0.6.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.