Skip to content
Merged
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
12 changes: 6 additions & 6 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ jobs:

steps:
- uses: actions/checkout@v4
- name: Set up Python 3.8
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: 3.8
python-version: "3.10"
- uses: pre-commit/[email protected]

tests:
Expand All @@ -30,7 +30,7 @@ jobs:
strategy:
fail-fast: false
matrix:
python-version: ['pypy-3.8', '3.8', '3.9', '3.10', '3.11', '3.12']
python-version: ['pypy-3.10', '3.10', '3.11', '3.12', '3.13']

steps:
- uses: actions/checkout@v4
Expand All @@ -46,13 +46,13 @@ jobs:
run: |
pytest --cov=mdit_py_plugins --cov-report=xml --cov-report=term-missing
- name: Upload to Codecov
uses: codecov/codecov-action@v3
uses: codecov/codecov-action@v5
if: github.event.pull_request.head.repo.full_name == github.repository
with:
token: ${{ secrets.CODECOV_TOKEN }}
name: mdit-py-plugins-pytests
flags: pytests
file: ./coverage.xml
files: ./coverage.xml
fail_ci_if_error: true

allgood:
Expand All @@ -75,7 +75,7 @@ jobs:
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.8"
python-version: "3.10"
- name: install flit
run: |
pip install flit~=3.4
Expand Down
6 changes: 3 additions & 3 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,22 @@ exclude: >
repos:

- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.6.0
rev: v6.0.0
hooks:
- id: check-json
- id: check-yaml
- id: end-of-file-fixer
- id: trailing-whitespace

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

- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.10.0
rev: v1.17.1
hooks:
- id: mypy
additional_dependencies: [markdown-it-py~=3.0]
Expand Down
3 changes: 2 additions & 1 deletion .readthedocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ version: 2
build:
os: ubuntu-22.04
tools:
python: "3.8"
python: "3.10"

python:
install:
Expand All @@ -12,5 +12,6 @@ python:
extra_requirements: [rtd]

sphinx:
configuration: docs/conf.py
builder: html
fail_on_warning: true
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Change Log

## 0.5.0 - 2025-08-11

- ⬆️ Drop Python 3.9, which is EoL next month <https://devguide.python.org/versions> and allow for the, soon to be released, markdown-it-py v4.
- ✨ NEW: Add plugin & tests to render subscripts, thanks to @miteshashar

## 0.4.2 - 2024-09-09

- 👌 Improve parsing of nested amsmath
Expand Down
2 changes: 1 addition & 1 deletion mdit_py_plugins/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "0.4.2"
__version__ = "0.5.0"
3 changes: 2 additions & 1 deletion mdit_py_plugins/admon/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@

from __future__ import annotations

from collections.abc import Callable, Sequence
from contextlib import suppress
import re
from typing import TYPE_CHECKING, Callable, Sequence
from typing import TYPE_CHECKING

from markdown_it import MarkdownIt
from markdown_it.rules_block import StateBlock
Expand Down
3 changes: 2 additions & 1 deletion mdit_py_plugins/amsmath/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@

from __future__ import annotations

from collections.abc import Callable, Sequence
import re
from typing import TYPE_CHECKING, Callable, Sequence
from typing import TYPE_CHECKING

from markdown_it import MarkdownIt
from markdown_it.common.utils import escapeHtml
Expand Down
10 changes: 5 additions & 5 deletions mdit_py_plugins/anchors/index.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from collections.abc import Callable
import re
from typing import Callable, List, Optional, Set

from markdown_it import MarkdownIt
from markdown_it.rules_core import StateCore
Expand All @@ -10,7 +10,7 @@ def anchors_plugin(
md: MarkdownIt,
min_level: int = 1,
max_level: int = 2,
slug_func: Optional[Callable[[str], str]] = None,
slug_func: Callable[[str], str] | None = None,
permalink: bool = False,
permalinkSymbol: str = "¶",
permalinkBefore: bool = False,
Expand Down Expand Up @@ -58,15 +58,15 @@ def anchors_plugin(


def _make_anchors_func(
selected_levels: List[int],
selected_levels: list[int],
slug_func: Callable[[str], str],
permalink: bool,
permalinkSymbol: str,
permalinkBefore: bool,
permalinkSpace: bool,
) -> Callable[[StateCore], None]:
def _anchor_func(state: StateCore) -> None:
slugs: Set[str] = set()
slugs: set[str] = set()
for idx, token in enumerate(state.tokens):
if token.type != "heading_open":
continue
Expand Down Expand Up @@ -119,7 +119,7 @@ def slugify(title: str) -> str:
return re.sub(r"[^\w\u4e00-\u9fff\- ]", "", title.strip().lower().replace(" ", "-"))


def unique_slug(slug: str, slugs: Set[str]) -> str:
def unique_slug(slug: str, slugs: set[str]) -> str:
uniq = slug
i = 1
while uniq in slugs:
Expand Down
3 changes: 2 additions & 1 deletion mdit_py_plugins/attrs/index.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
from __future__ import annotations

from collections.abc import Sequence
from functools import partial
from typing import Any, Sequence
from typing import Any

from markdown_it import MarkdownIt
from markdown_it.rules_block import StateBlock
Expand Down
2 changes: 1 addition & 1 deletion mdit_py_plugins/attrs/parse.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ class <- '.' name

from __future__ import annotations

from collections.abc import Callable
from enum import Enum
import re
from typing import Callable


class State(Enum):
Expand Down
3 changes: 2 additions & 1 deletion mdit_py_plugins/colon_fence.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from __future__ import annotations

from typing import TYPE_CHECKING, Sequence
from collections.abc import Sequence
from typing import TYPE_CHECKING

from markdown_it import MarkdownIt
from markdown_it.common.utils import escapeHtml, unescapeAll
Expand Down
3 changes: 2 additions & 1 deletion mdit_py_plugins/container/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@

from __future__ import annotations

from collections.abc import Callable, Sequence
from math import floor
from typing import TYPE_CHECKING, Any, Callable, Sequence
from typing import TYPE_CHECKING, Any

from markdown_it import MarkdownIt
from markdown_it.rules_block import StateBlock
Expand Down
5 changes: 3 additions & 2 deletions mdit_py_plugins/dollarmath/index.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
from __future__ import annotations

from collections.abc import Callable, Sequence
import re
from typing import TYPE_CHECKING, Any, Callable, Sequence
from typing import TYPE_CHECKING, Any

from markdown_it import MarkdownIt
from markdown_it.common.utils import escapeHtml, isWhiteSpace
Expand Down Expand Up @@ -146,7 +147,7 @@ def is_escaped(state: StateInline, back_pos: int, mod: int = 0) -> bool:
return False

# if an odd number of \ then ignore
if (backslashes % 2) != mod:
if (backslashes % 2) != mod: # noqa: SIM103
return True

return False
Expand Down
6 changes: 3 additions & 3 deletions mdit_py_plugins/field_list/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""Field list plugin"""

from collections.abc import Iterator
from contextlib import contextmanager
from typing import Iterator, Optional, Tuple

from markdown_it import MarkdownIt
from markdown_it.rules_block import StateBlock
Expand Down Expand Up @@ -45,7 +45,7 @@ def fieldlist_plugin(md: MarkdownIt) -> None:
)


def parseNameMarker(state: StateBlock, startLine: int) -> Tuple[int, str]:
def parseNameMarker(state: StateBlock, startLine: int) -> tuple[int, str]:
"""Parse field name: `:name:`

:returns: position after name marker, name text
Expand Down Expand Up @@ -159,7 +159,7 @@ def _fieldlist_rule(

# to figure out the indent of the body,
# we look at all non-empty, indented lines and find the minimum indent
block_indent: Optional[int] = None
block_indent: int | None = None
_line = startLine + 1
while _line < endLine:
# if start_of_content < end_of_content, then non-empty line
Expand Down
5 changes: 3 additions & 2 deletions mdit_py_plugins/footnote/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@

from __future__ import annotations

from collections.abc import Sequence
from functools import partial
from typing import TYPE_CHECKING, Sequence, TypedDict
from typing import TYPE_CHECKING, TypedDict

from markdown_it import MarkdownIt
from markdown_it.helpers import parseLinkLabel
Expand Down Expand Up @@ -332,7 +333,7 @@ def footnote_tail(state: StateCore) -> None:

tok_filter.append(not insideRef)

state.tokens = [t for t, f in zip(state.tokens, tok_filter) if f]
state.tokens = [t for t, f in zip(state.tokens, tok_filter, strict=False) if f]

footnote_data = _data_from_env(state.env)
if not footnote_data["list"]:
Expand Down
3 changes: 2 additions & 1 deletion mdit_py_plugins/myst_blocks/index.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
from __future__ import annotations

from collections.abc import Sequence
import itertools
from typing import TYPE_CHECKING, Sequence
from typing import TYPE_CHECKING

from markdown_it import MarkdownIt
from markdown_it.common.utils import escapeHtml
Expand Down
3 changes: 2 additions & 1 deletion mdit_py_plugins/myst_role/index.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from collections.abc import Sequence
import re
from typing import TYPE_CHECKING, Sequence
from typing import TYPE_CHECKING

from markdown_it import MarkdownIt
from markdown_it.common.utils import escapeHtml
Expand Down
6 changes: 4 additions & 2 deletions mdit_py_plugins/texmath/index.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
from __future__ import annotations

from collections.abc import Callable, Sequence
import re
from typing import TYPE_CHECKING, Any, Callable, Match, Sequence, TypedDict
from re import Match
from typing import TYPE_CHECKING, Any, TypedDict

from markdown_it import MarkdownIt
from markdown_it.common.utils import charCodeAt
Expand Down Expand Up @@ -152,7 +154,7 @@ def _func(state: StateBlock, begLine: int, endLine: int, silent: bool) -> bool:
def dollar_pre(src: str, beg: int) -> bool:
prv = charCodeAt(src[beg - 1], 0) if beg > 0 else False
return (
(not prv) or prv != 0x5C and (prv < 0x30 or prv > 0x39) # no backslash,
(not prv) or (prv != 0x5C and (prv < 0x30 or prv > 0x39)) # no backslash,
) # no decimal digit .. before opening '$'


Expand Down
6 changes: 3 additions & 3 deletions mdit_py_plugins/wordcount/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from collections.abc import Callable
import string
from typing import Callable, List

from markdown_it import MarkdownIt
from markdown_it.rules_core import StateCore
Expand Down Expand Up @@ -33,7 +33,7 @@ def wordcount_plugin(
"""

def _word_count_rule(state: StateCore) -> None:
text: List[str] = []
text: list[str] = []
words = 0
for token in state.tokens:
if token.type == "text":
Expand All @@ -53,6 +53,6 @@ def _word_count_rule(state: StateCore) -> None:
data["text"] += text
data.setdefault("words", 0)
data["words"] += words
data["minutes"] = int(round(data["words"] / per_minute))
data["minutes"] = int(round(data["words"] / per_minute)) # noqa: RUF046

md.core.ruler.push("wordcount", _word_count_rule)
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ classifiers = [
"Topic :: Text Processing :: Markup",
]
keywords = ["markdown", "markdown-it", "lexer", "parser", "development"]
requires-python = ">=3.8"
dependencies = ["markdown-it-py>=1.0.0,<4.0.0"]
requires-python = ">=3.10"
dependencies = ["markdown-it-py>=2.0.0,<5.0.0"]

[project.urls]
Homepage = "https://github.com/executablebooks/mdit-py-plugins"
Expand Down
6 changes: 3 additions & 3 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,18 @@
# then run `tox` or `tox -- {pytest args}`
# run in parallel using `tox -p`
[tox]
envlist = py38
envlist = py310

[testenv]
usedevelop = true

[testenv:py{38,39,310,311,312}]
[testenv:py{310,311,312,313}]
extras = testing
commands = pytest {posargs}

[testenv:docs-{update,clean}]
extras = rtd
whitelist_externals = rm
allowlist_externals = rm
commands =
clean: rm -rf docs/_build
sphinx-build -nW --keep-going -b {posargs:html} docs/ docs/_build/{posargs:html}