diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 1102284..6564eea 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -20,14 +20,14 @@ repos: - id: trailing-whitespace - repo: https://github.com/astral-sh/ruff-pre-commit - rev: v0.15.12 + rev: v0.16.5 hooks: - id: ruff args: [--fix] - id: ruff-format - repo: https://github.com/pre-commit/mirrors-mypy - rev: v1.20.2 + rev: v2.3.1 hooks: - id: mypy additional_dependencies: [markdown-it-py~=3.0] diff --git a/AGENTS.md b/AGENTS.md index 122a8d2..107ba52 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -215,7 +215,7 @@ plugin_name/ Plugins create and manipulate markdown-it tokens: ```python -token = state.push("my_type_open", "div", 1) # Opening tag +token = state.push("my_type_open", "div", 1) # Opening tag token.attrSet("class", "my-class") token.markup = "..." token.map = [startLine, nextLine] @@ -302,6 +302,7 @@ print(md.render("Some $inline$ math")) ```python from markdown_it import MarkdownIt + def my_plugin(md: MarkdownIt) -> None: md.block.ruler.before("fence", "my_rule", _my_rule) md.add_render_rule("my_type", _render_my_type) @@ -318,6 +319,7 @@ Block rules receive `(state: StateBlock, startLine: int, endLine: int, silent: b ```python from markdown_it.rules_block import StateBlock + def my_block_rule( state: StateBlock, startLine: int, endLine: int, silent: bool ) -> bool: @@ -348,6 +350,7 @@ Inline rules receive `(state: StateInline, silent: bool) -> bool`: ```python from markdown_it.rules_inline import StateInline + def my_inline_rule(state: StateInline, silent: bool) -> bool: if state.src[state.pos] != "$": return False diff --git a/docs/index.md b/docs/index.md index 123ab6a..1929fe0 100644 --- a/docs/index.md +++ b/docs/index.md @@ -11,13 +11,15 @@ These can be enabled individually: ```python from markdown_it import MarkdownIt -md = MarkdownIt("commonmark").enable('table') + +md = MarkdownIt("commonmark").enable("table") ``` or as part of a configuration: ```python from markdown_it import MarkdownIt + md = MarkdownIt("gfm-like") ``` @@ -33,6 +35,7 @@ They can be chained and loaded *via*: ```python from markdown_it import MarkdownIt from mdit_py_plugins import plugin1, plugin2 + md = MarkdownIt().use(plugin1, keyword=value).use(plugin2, keyword=value) html_string = md.render("some *Markdown*") ``` diff --git a/mdit_py_plugins/admon/index.py b/mdit_py_plugins/admon/index.py index 6e28940..c8933dc 100644 --- a/mdit_py_plugins/admon/index.py +++ b/mdit_py_plugins/admon/index.py @@ -183,7 +183,7 @@ def admonition(state: StateBlock, startLine: int, endLine: int, silent: bool) -> return True -def admon_plugin(md: MarkdownIt, render: None | Callable[..., str] = None) -> None: +def admon_plugin(md: MarkdownIt, render: Callable[..., str] | None = None) -> None: """Plugin to use `python-markdown style admonitions `_. diff --git a/mdit_py_plugins/container/index.py b/mdit_py_plugins/container/index.py index c610268..3338f30 100644 --- a/mdit_py_plugins/container/index.py +++ b/mdit_py_plugins/container/index.py @@ -21,8 +21,8 @@ def container_plugin( md: MarkdownIt, name: str, marker: str = ":", - validate: None | Callable[[str, str], bool] = None, - render: None | Callable[..., str] = None, + validate: Callable[[str, str], bool] | None = None, + render: Callable[..., str] | None = None, ) -> None: """Plugin ported from `markdown-it-container `__. diff --git a/mdit_py_plugins/dollarmath/index.py b/mdit_py_plugins/dollarmath/index.py index 57ba590..43727c1 100644 --- a/mdit_py_plugins/dollarmath/index.py +++ b/mdit_py_plugins/dollarmath/index.py @@ -54,7 +54,7 @@ def dollarmath_plugin( """ if label_normalizer is None: - label_normalizer = lambda label: re.sub(r"\s+", "-", label) # noqa: E731 + label_normalizer = lambda label: re.sub(r"\s+", "-", label) md.inline.ruler.before( "escape", @@ -77,10 +77,8 @@ def dollarmath_plugin( _label_renderer: Callable[[str], str] if label_renderer is None: - _label_renderer = ( # noqa: E731 - lambda label: ( - f'' - ) + _label_renderer = lambda label: ( + f'' ) else: _label_renderer = label_renderer diff --git a/mdit_py_plugins/texmath/index.py b/mdit_py_plugins/texmath/index.py index 67372fa..51525a0 100644 --- a/mdit_py_plugins/texmath/index.py +++ b/mdit_py_plugins/texmath/index.py @@ -86,7 +86,7 @@ class RuleDictType(_RuleDictReqType, total=False): def applyRule( rule: RuleDictType, string: str, begin: int, inBlockquote: bool -) -> None | Match[str]: +) -> Match[str] | None: if not ( string.startswith(rule["tag"], begin) and (rule["pre"](string, begin) if "pre" in rule else True) @@ -202,14 +202,15 @@ def render(tex: str, displayMode: bool, macros: Any) -> str: { "name": "math_block_eqno", "rex": re.compile( - r"^\\\[(((?!\\\]|\\\[)[\s\S])+?)\\\]\s*?\(([^)$\r\n]+?)\)", re.M + r"^\\\[(((?!\\\]|\\\[)[\s\S])+?)\\\]\s*?\(([^)$\r\n]+?)\)", + re.MULTILINE, ), "tmpl": '
{0}({1})
', "tag": "\\[", }, { "name": "math_block", - "rex": re.compile(r"^\\\[([\s\S]+?)\\\]", re.M), + "rex": re.compile(r"^\\\[([\s\S]+?)\\\]", re.MULTILINE), "tmpl": "
\n{0}\n
\n", "tag": "\\[", }, @@ -228,14 +229,14 @@ def render(tex: str, displayMode: bool, macros: Any) -> str: { "name": "math_block_eqno", "rex": re.compile( - r"^`{3}math\s+?([^`]+?)\s+?`{3}\s*?\(([^)$\r\n]+?)\)", re.M + r"^`{3}math\s+?([^`]+?)\s+?`{3}\s*?\(([^)$\r\n]+?)\)", re.MULTILINE ), "tmpl": '
\n{0}({1})\n
\n', "tag": "```math", }, { "name": "math_block", - "rex": re.compile(r"^`{3}math\s+?([^`]+?)\s+?`{3}", re.M), + "rex": re.compile(r"^`{3}math\s+?([^`]+?)\s+?`{3}", re.MULTILINE), "tmpl": "
\n{0}\n
\n", "tag": "```math", }, @@ -270,14 +271,14 @@ def render(tex: str, displayMode: bool, macros: Any) -> str: { "name": "math_block_eqno", "rex": re.compile( - r"^`{3}math\s+?([^`]+?)\s+?`{3}\s*?\(([^)$\r\n]+?)\)", re.M + r"^`{3}math\s+?([^`]+?)\s+?`{3}\s*?\(([^)$\r\n]+?)\)", re.MULTILINE ), "tmpl": '
{0}({1})
', "tag": "```math", }, { "name": "math_block", - "rex": re.compile(r"^`{3}math\s+?([^`]+?)\s+?`{3}", re.M), + "rex": re.compile(r"^`{3}math\s+?([^`]+?)\s+?`{3}", re.MULTILINE), "tmpl": "
{0}
", "tag": "```math", }, @@ -295,13 +296,15 @@ def render(tex: str, displayMode: bool, macros: Any) -> str: "block": [ { "name": "math_block_eqno", - "rex": re.compile(r"^\${2}([^$]*?)\${2}\s*?\(([^)$\r\n]+?)\)", re.M), + "rex": re.compile( + r"^\${2}([^$]*?)\${2}\s*?\(([^)$\r\n]+?)\)", re.MULTILINE + ), "tmpl": '
{0}({1})
', "tag": "$$", }, { "name": "math_block", - "rex": re.compile(r"^\${2}([^$]*?)\${2}", re.M), + "rex": re.compile(r"^\${2}([^$]*?)\${2}", re.MULTILINE), "tmpl": "
{0}
", "tag": "$$", }, @@ -329,13 +332,15 @@ def render(tex: str, displayMode: bool, macros: Any) -> str: "block": [ { "name": "math_block_eqno", - "rex": re.compile(r"^\${2}([^$]*?)\${2}\s*?\(([^)$\r\n]+?)\)", re.M), + "rex": re.compile( + r"^\${2}([^$]*?)\${2}\s*?\(([^)$\r\n]+?)\)", re.MULTILINE + ), "tmpl": '
\n{0}({1})\n
\n', "tag": "$$", }, { "name": "math_block", - "rex": re.compile(r"^\${2}([^$]*?)\${2}", re.M), + "rex": re.compile(r"^\${2}([^$]*?)\${2}", re.MULTILINE), "tmpl": "
\n{0}\n
\n", "tag": "$$", },