Skip to content
Open
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
4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@ repos:
- id: trailing-whitespace

- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.15.12
rev: v0.16.0
hooks:
- id: ruff
args: [--fix]
- id: ruff-format

- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.20.2
rev: v2.3.0
hooks:
- id: mypy
additional_dependencies: [markdown-it-py~=3.0]
Expand Down
2 changes: 1 addition & 1 deletion mdit_py_plugins/admon/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
<https://python-markdown.github.io/extensions/admonition>`_.
Expand Down
4 changes: 2 additions & 2 deletions mdit_py_plugins/container/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 <https://github.com/markdown-it/markdown-it-container>`__.
Expand Down
8 changes: 3 additions & 5 deletions mdit_py_plugins/dollarmath/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -77,10 +77,8 @@ def dollarmath_plugin(

_label_renderer: Callable[[str], str]
if label_renderer is None:
_label_renderer = ( # noqa: E731
lambda label: (
f'<a href="#{label}" class="mathlabel" title="Permalink to this equation">¶</a>'
)
_label_renderer = lambda label: (
f'<a href="#{label}" class="mathlabel" title="Permalink to this equation">¶</a>'
)
else:
_label_renderer = label_renderer
Expand Down
27 changes: 16 additions & 11 deletions mdit_py_plugins/texmath/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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": '<section class="eqno"><eqn>{0}</eqn><span>({1})</span></section>',
"tag": "\\[",
},
{
"name": "math_block",
"rex": re.compile(r"^\\\[([\s\S]+?)\\\]", re.M),
"rex": re.compile(r"^\\\[([\s\S]+?)\\\]", re.MULTILINE),
"tmpl": "<section>\n<eqn>{0}</eqn>\n</section>\n",
"tag": "\\[",
},
Expand All @@ -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": '<section class="eqno">\n<eqn>{0}</eqn><span>({1})</span>\n</section>\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": "<section>\n<eqn>{0}</eqn>\n</section>\n",
"tag": "```math",
},
Expand Down Expand Up @@ -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": '<section class="eqno"><eqn>{0}</eqn><span>({1})</span></section>',
"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": "<section><eqn>{0}</eqn></section>",
"tag": "```math",
},
Expand All @@ -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": '<section class="eqno"><eqn>{0}</eqn><span>({1})</span></section>',
"tag": "$$",
},
{
"name": "math_block",
"rex": re.compile(r"^\${2}([^$]*?)\${2}", re.M),
"rex": re.compile(r"^\${2}([^$]*?)\${2}", re.MULTILINE),
"tmpl": "<section><eqn>{0}</eqn></section>",
"tag": "$$",
},
Expand Down Expand Up @@ -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": '<section class="eqno">\n<eqn>{0}</eqn><span>({1})</span>\n</section>\n',
"tag": "$$",
},
{
"name": "math_block",
"rex": re.compile(r"^\${2}([^$]*?)\${2}", re.M),
"rex": re.compile(r"^\${2}([^$]*?)\${2}", re.MULTILINE),
"tmpl": "<section>\n<eqn>{0}</eqn>\n</section>\n",
"tag": "$$",
},
Expand Down
Loading