diff --git a/.gitignore b/.gitignore index 546e6c2a..0c136bb6 100644 --- a/.gitignore +++ b/.gitignore @@ -141,3 +141,5 @@ __pycache__/ .DS_Store docs/api/ + +uv.lock diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index d6005f6e..ebc6ab1d 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -34,7 +34,7 @@ repos: rev: v1.13.0 hooks: - id: mypy - additional_dependencies: [mdurl] + additional_dependencies: [mdurl, typing-extensions] exclude: > (?x)^( benchmarking/.*\.py| diff --git a/docs/conf.py b/docs/conf.py index dc1a28fd..3a40249d 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -55,6 +55,7 @@ "EnvType", "Path", "Ellipsis", + "NotRequired", ) ] diff --git a/docs/contributing.md b/docs/contributing.md index b2302046..eeb65e1c 100644 --- a/docs/contributing.md +++ b/docs/contributing.md @@ -32,7 +32,7 @@ All functions and class methods should be annotated with types and include a doc ## Testing -For code tests, markdown-it-py uses [pytest](https://docs.pytest.org)): +For code tests, markdown-it-py uses [pytest](https://docs.pytest.org): ```shell >> cd markdown-it-py diff --git a/markdown_it/utils.py b/markdown_it/utils.py index 86cfee7f..3d2a20e5 100644 --- a/markdown_it/utils.py +++ b/markdown_it/utils.py @@ -3,7 +3,11 @@ from collections.abc import Iterable, MutableMapping from collections.abc import MutableMapping as MutableMappingABC from pathlib import Path -from typing import Any, Callable, TypedDict, cast +from typing import TYPE_CHECKING, Any, Callable, TypedDict, cast + +if TYPE_CHECKING: + from typing_extensions import NotRequired + EnvType = MutableMapping[str, Any] # note: could use TypeAlias in python 3.10 """Type for the environment sandbox used in parsing and rendering, @@ -32,6 +36,11 @@ class OptionsType(TypedDict): """CSS language prefix for fenced blocks.""" highlight: Callable[[str, str, str], str] | None """Highlighter function: (content, lang, attrs) -> str.""" + store_labels: NotRequired[bool] + """Store link label in link/image token's metadata (under Token.meta['label']). + + This is a Python only option, and is intended for the use of round-trip parsing. + """ class PresetType(TypedDict): diff --git a/pyproject.toml b/pyproject.toml index aa13fadf..d46668a0 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -70,6 +70,9 @@ benchmarking = [ ] profiling = ["gprof2dot"] +[dependency-groups] +mypy = ["mypy", "mdurl", "typing-extensions"] + [project.scripts] markdown-it = "markdown_it.cli.parse:main" @@ -106,7 +109,7 @@ module = ["tests.test_plugins.*", "markdown.*"] ignore_errors = true [[tool.mypy.overrides]] -module = ["markdown.*"] +module = ["markdown.*", "linkify_it.*"] ignore_missing_imports = true [tool.pytest.ini_options]