Skip to content

Commit

Permalink
fix: type-based imports
Browse files Browse the repository at this point in the history
  • Loading branch information
antazoey committed Dec 19, 2024
1 parent 93bb972 commit 1872139
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions mdformat_frontmatter/plugin.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
import io
import sys
from typing import Mapping
from typing import Mapping, TYPE_CHECKING

from markdown_it import MarkdownIt
import mdformat.renderer
from mdformat.renderer import RenderContext, RenderTreeNode
from mdformat.renderer.typing import Render

from mdit_py_plugins.front_matter import front_matter_plugin
import ruamel.yaml

if TYPE_CHECKING:
from mdformat.renderer import RenderContext, RenderTreeNode
from mdformat.renderer.typing import Render


yaml = ruamel.yaml.YAML()
# Make sure to always have `sequence >= offset + 2`
yaml.indent(mapping=2, sequence=4, offset=2)
Expand All @@ -20,7 +23,7 @@ def update_mdit(mdit: MarkdownIt) -> None:
mdit.use(front_matter_plugin)


def _render_frontmatter(node: RenderTreeNode, context: RenderContext) -> str:
def _render_frontmatter(node: "RenderTreeNode", context: "RenderContext") -> str:
# Safety check - parse and dump yaml to ensure it is correctly formatted
dump_stream = io.StringIO()
try:
Expand All @@ -39,4 +42,4 @@ def _render_frontmatter(node: RenderTreeNode, context: RenderContext) -> str:


# apply the render function to the block identified by the mdit plugin
RENDERERS: Mapping[str, Render] = {"front_matter": _render_frontmatter}
RENDERERS: Mapping[str, "Render"] = {"front_matter": _render_frontmatter}

0 comments on commit 1872139

Please sign in to comment.