diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 1102284..1b32767 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.17.4 hooks: - id: ruff args: [--fix] - id: ruff-format - repo: https://github.com/pre-commit/mirrors-mypy - rev: v1.20.2 + rev: v2.4.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 04ce054..d3ad724 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") ``` diff --git a/mdit_py_plugins/admon/index.py b/mdit_py_plugins/admon/index.py index 8d58c22..88283c3 100644 --- a/mdit_py_plugins/admon/index.py +++ b/mdit_py_plugins/admon/index.py @@ -188,7 +188,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/texmath/index.py b/mdit_py_plugins/texmath/index.py index 58a1bb7..1847ba1 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) @@ -210,14 +210,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": "\\[", }, @@ -237,7 +238,7 @@ def render(tex: str, displayMode: bool, macros: Any) -> str: "name": "math_block_eqno", "rex": re.compile( r"^`{3}math\s(\s*[^`\s](?:[^`]*[^`\s])?|\s)\s+`{3}\s*?\(([^)$\r\n]+?)\)", - re.M, + re.MULTILINE, ), "tmpl": '
\n{0}({1})\n
\n', "tag": "```math", @@ -245,7 +246,7 @@ def render(tex: str, displayMode: bool, macros: Any) -> str: { "name": "math_block", "rex": re.compile( - r"^`{3}math\s(\s*[^`\s](?:[^`]*[^`\s])?|\s)\s+`{3}", re.M + r"^`{3}math\s(\s*[^`\s](?:[^`]*[^`\s])?|\s)\s+`{3}", re.MULTILINE ), "tmpl": "
\n{0}\n
\n", "tag": "```math", @@ -282,7 +283,7 @@ def render(tex: str, displayMode: bool, macros: Any) -> str: "name": "math_block_eqno", "rex": re.compile( r"^`{3}math\s(\s*[^`\s](?:[^`]*[^`\s])?|\s)\s+`{3}\s*?\(([^)$\r\n]+?)\)", - re.M, + re.MULTILINE, ), "tmpl": '
{0}({1})
', "tag": "```math", @@ -290,7 +291,7 @@ def render(tex: str, displayMode: bool, macros: Any) -> str: { "name": "math_block", "rex": re.compile( - r"^`{3}math\s(\s*[^`\s](?:[^`]*[^`\s])?|\s)\s+`{3}", re.M + r"^`{3}math\s(\s*[^`\s](?:[^`]*[^`\s])?|\s)\s+`{3}", re.MULTILINE ), "tmpl": "
{0}
", "tag": "```math", @@ -309,13 +310,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": "$$", }, @@ -343,13 +346,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": "$$", }, diff --git a/pyproject.toml b/pyproject.toml index 5d7b19c..f6746e4 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -56,6 +56,8 @@ exclude = [ ] [tool.ruff.lint] +# Pin the base rule set (ruff >=0.16 grew its default set); extend it deliberately below. +select = ["E4", "E7", "E9", "F"] extend-select = [ "B", # flake8-bugbear "C4", # flake8-comprehensions