Skip to content

Commit

Permalink
create markdown parser
Browse files Browse the repository at this point in the history
  • Loading branch information
kjaymiller committed Dec 10, 2023
1 parent ede4fbf commit 6a779da
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 6 deletions.
7 changes: 7 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"python.testing.pytestArgs": [
"."
],
"python.testing.unittestEnabled": false,
"python.testing.pytestEnabled": true
}
43 changes: 43 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
[build-system]
requires = ["setuptools", "setuptools_scm", "wheel"]
build-backend = "setuptools.build_meta"

[project]
name = "render_engine_markdown"
dynamic = ["version"]
description = "Markdown Parser for Render Engine"
readme = "README.md"
requires-python = ">=3.10"
dependencies = [
"markdown2",
]

[project.optional-dependencies]
dev = [
"pytest",
"pytest-cov",
"ruff",
]

[tool.setuptools_scm]
local_scheme = "no-local-version"
# version_scheme = "python-simplified-semver"

[project.urls]
homepage = "https://github.com/kjaymiller/render_engine/"
repository = "https://github.com/kjaymiller/render_engine/"
documentation = "https://render-engine.readthedocs.io/en/latest/"

[tool.pytest.ini_options]
addopts = "-ra -q --cov"

[tool.semantic_release]
version_toml = "pyproject.toml:project.version"
branch = "main"

[tool.ruff]
select = ["E", "F", "I", "UP"]
target-version = "py311"
line-length = 120
src = ["src"]
ignore-init-module-imports = true
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
# ruff: noqa: F821

from markdown2 import markdown

from ..base_parsers import BasePageParser
from render_engine_parser import BasePageParser

__all__ = ["BasePageParser"]

Expand All @@ -14,8 +13,9 @@ class MarkdownPageParser(BasePageParser):
"""

@staticmethod
def parse(content: str, page: "Page") -> str:
def parse(content: str, extras: dict[str, any] | None = None ) -> str:
"""Parses the content with the parser"""
extras = getattr(page, "parser_extras", {})
markup = markdown(content, extras=extras.get("markdown_extras", []))
return markup
return markdown(
content,
extras=extras.get("markdown_extras", []) if extras else [],
)
16 changes: 16 additions & 0 deletions tests/test_parser_markdown_parser.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import pytest
from render_engine_markdown import MarkdownPageParser


@pytest.fixture()
def markdown_content():
return """# Test"""


def test_parser_parse_content(markdown_content):
assert (
MarkdownPageParser.parse(
content=markdown_content,
)
== "<h1>Test</h1>\n"
)

0 comments on commit 6a779da

Please sign in to comment.