Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,22 +1,21 @@
# Render Engine `BasePageParser`

The `BasePageParser` is used for making content for Render Engine. Parsers are used to parse the content of a page and convert it to HTML. The parser is specified in the page attributes as `Parser`.

Check failure on line 3 in README.md

View workflow job for this annotation

GitHub Actions / build

Line length

README.md:3:81 MD013/line-length Line length [Expected: 80; Actual: 198] https://github.com/DavidAnson/markdownlint/blob/v0.32.1/doc/md013.md

This is meant to be used by Render Enging but can be used as a base dependency for building custom Render Engine Parsers.

Check failure on line 5 in README.md

View workflow job for this annotation

GitHub Actions / build

Line length

README.md:5:81 MD013/line-length Line length [Expected: 80; Actual: 121] https://github.com/DavidAnson/markdownlint/blob/v0.32.1/doc/md013.md

## Using Frontmatter

[Frontmatter](https://github.com/eyeseast/python-frontmatter) is used to pull in attributes from a generated page.

Check failure on line 9 in README.md

View workflow job for this annotation

GitHub Actions / build

Line length

README.md:9:81 MD013/line-length Line length [Expected: 80; Actual: 114] https://github.com/DavidAnson/markdownlint/blob/v0.32.1/doc/md013.md

Some pages will be looking for information that is provided in the frontmatter. All of the attributes defined can be used in the template (which itself can also be defined in the frontmatter or the class itself.

Check failure on line 11 in README.md

View workflow job for this annotation

GitHub Actions / build

Line length

README.md:11:81 MD013/line-length Line length [Expected: 80; Actual: 211] https://github.com/DavidAnson/markdownlint/blob/v0.32.1/doc/md013.md

> **NOTE**
> These attributes **CANNOT** be used in the content itself, but you can use them in the template generation.

Check failure on line 14 in README.md

View workflow job for this annotation

GitHub Actions / build

Line length

README.md:14:81 MD013/line-length Line length [Expected: 80; Actual: 109] https://github.com/DavidAnson/markdownlint/blob/v0.32.1/doc/md013.md


## Parsing the Data

The base parser doesn't is a pass-thru parser meaning the content input will be passed through.

Check failure on line 18 in README.md

View workflow job for this annotation

GitHub Actions / build

Line length

README.md:18:81 MD013/line-length Line length [Expected: 80; Actual: 95] https://github.com/DavidAnson/markdownlint/blob/v0.32.1/doc/md013.md

```md
---
Expand Down
16 changes: 16 additions & 0 deletions render_engine_parser/base_parsers.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,3 +62,19 @@ def parse(
extras: dictionary with extras to augment attributes
"""
return content

@staticmethod
def create_entry(*, filepath: pathlib.Path | None, content: str = "Hello World", **kwargs) -> str:
"""
Writes the content type that would be parsed to the content_path.

attrs:
filepath: Only used if reading from an existing path
"""

post = frontmatter.Post(content)

for key, val in kwargs.items():
post[key] = val

return frontmatter.dumps(post)
26 changes: 26 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#
# This file is autogenerated by pip-compile with Python 3.13
# by the following command:
#
# pip-compile --extra=dev
#
coverage[toml]==7.6.1
# via pytest-cov
iniconfig==2.0.0
# via pytest
packaging==24.1
# via pytest
pluggy==1.5.0
# via pytest
pytest==8.3.2
# via
# pytest-cov
# render_engine_parser (pyproject.toml)
pytest-cov==5.0.0
# via render_engine_parser (pyproject.toml)
python-frontmatter==1.1.0
# via render_engine_parser (pyproject.toml)
pyyaml==6.0.2
# via python-frontmatter
ruff==0.6.4
# via render_engine_parser (pyproject.toml)
15 changes: 15 additions & 0 deletions tests/test_base_parser.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import frontmatter
import pytest

from render_engine_parser.base_parsers import BasePageParser, parse_content
Expand Down Expand Up @@ -52,3 +53,17 @@ def test_base_parser_parse_content_path(base_content_path):

expected_result = ({"title": "This is a Test"}, "# This is a Test")
assert expected_result == BasePageParser.parse_content_path(base_content_path)


def test_base_parser_net_entry():
data = BasePageParser.create_entry(
filepath=None, # reminder this is ignored in the base case
content="This is a Test",
title="Untitled Entry",
slug="untitled-entry",
)

post = frontmatter.loads(data)
assert post["title"] == "Untitled Entry"
assert post["slug"] == "untitled-entry"
assert post.content == "This is a Test"
Loading