Big News: Socket raises $60M Series C at a $1B valuation to secure software supply chains for AI-driven development.Announcement
Sign In

mkdocstrings

Package Overview
Dependencies
Maintainers
1
Versions
75
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mkdocstrings - pypi Package Compare versions

Comparing version
0.24.0
to
0.24.1
+16
tests/fixtures/markdown_anchors.py
"""Module docstring.
[](){#anchor}
Paragraph.
[](){#heading-anchor-1}
[](){#heading-anchor-2}
[](){#heading-anchor-3}
## Heading
[](#has-href1)
[](#has-href2){#with-id}
Pararaph.
"""
+3
-6
Metadata-Version: 2.1
Name: mkdocstrings
Version: 0.24.0
Version: 0.24.1
Summary: Automatic documentation from sources, for MkDocs.
Keywords: mkdocs mkdocs-plugin docstrings autodoc documentation
Author-Email: Timothée Mazzucotelli <pawamoy@pm.me>
Author-Email: Timothée Mazzucotelli <dev@pawamoy.fr>
License: ISC

@@ -59,3 +59,3 @@ Classifier: Development Status :: 4 - Beta

Automatic documentation from sources, for [MkDocs](https://mkdocs.org/).
Automatic documentation from sources, for [MkDocs](https://www.mkdocs.org/).
Come have a chat or ask questions on our [Gitter channel](https://gitter.im/mkdocstrings/community).

@@ -109,5 +109,2 @@

- ~~**Watch source code directories:**~~
this feature was removed as it is now [built in MkDocs](https://www.mkdocs.org/user-guide/configuration/#watch).
- **Reasonable defaults:**

@@ -114,0 +111,0 @@ you should be able to just drop the plugin in your configuration and enjoy your auto-generated docs.

@@ -11,3 +11,3 @@ [build-system]

authors = [
{ name = "Timothée Mazzucotelli", email = "pawamoy@pm.me" },
{ name = "Timothée Mazzucotelli", email = "dev@pawamoy.fr" },
]

@@ -53,3 +53,3 @@ readme = "README.md"

]
version = "0.24.0"
version = "0.24.1"

@@ -56,0 +56,0 @@ [project.license]

@@ -10,3 +10,3 @@ # mkdocstrings

Automatic documentation from sources, for [MkDocs](https://mkdocs.org/).
Automatic documentation from sources, for [MkDocs](https://www.mkdocs.org/).
Come have a chat or ask questions on our [Gitter channel](https://gitter.im/mkdocstrings/community).

@@ -60,5 +60,2 @@

- ~~**Watch source code directories:**~~
this feature was removed as it is now [built in MkDocs](https://www.mkdocs.org/user-guide/configuration/#watch).
- **Reasonable defaults:**

@@ -65,0 +62,0 @@ you should be able to just drop the plugin in your configuration and enjoy your auto-generated docs.

"""This module holds the code of the Markdown extension responsible for matching "autodoc" instructions.
The extension is composed of a Markdown [block processor](https://python-markdown.github.io/extensions/api/#blockparser)
that matches indented blocks starting with a line like '::: identifier'.
that matches indented blocks starting with a line like `::: identifier`.

@@ -6,0 +6,0 @@ For each of these blocks, it uses a [handler][mkdocstrings.handlers.base.BaseHandler] to collect documentation about

@@ -46,2 +46,3 @@ """This module holds helpers responsible for augmentations to the Markdown sub-documents produced by handlers."""

"guess_lang",
"default_lang",
"pygments_style",

@@ -62,2 +63,4 @@ "noclasses",

"line_anchors",
"pygments_lang_class",
"stripnl",
),

@@ -151,15 +154,31 @@ )

def run(self, root: Element) -> None: # noqa: D102 (ignore missing docstring)
if not self.id_prefix:
return
for el in root.iter():
id_attr = el.get("id")
if id_attr:
el.set("id", self.id_prefix + id_attr)
if self.id_prefix:
self._prefix_ids(root)
def _prefix_ids(self, root: Element) -> None:
index = len(root)
for el in reversed(root): # Reversed mainly for the ability to mutate during iteration.
index -= 1
self._prefix_ids(el)
href_attr = el.get("href")
if id_attr := el.get("id"):
if el.tag == "a" and not href_attr:
# An anchor with id and no href is used by autorefs:
# leave it untouched and insert a copy with updated id after it.
new_el = copy.deepcopy(el)
new_el.set("id", self.id_prefix + id_attr)
root.insert(index + 1, new_el)
else:
# Anchors with id and href are not used by autorefs:
# update in place.
el.set("id", self.id_prefix + id_attr)
# Always update hrefs, names and labels-for:
# there will always be a corresponding id.
if href_attr and href_attr.startswith("#"):
el.set("href", "#" + self.id_prefix + href_attr[1:])
name_attr = el.get("name")
if name_attr:
if name_attr := el.get("name"):
el.set("name", self.id_prefix + name_attr)

@@ -166,0 +185,0 @@

@@ -175,1 +175,48 @@ """Tests for the extension module."""

assert output.count('class="mkdocstrings') == 0
def _assert_contains_in_order(items: list[str], string: str) -> None:
index = 0
for item in items:
assert item in string[index:]
index = string.index(item, index) + len(item)
@pytest.mark.parametrize("ext_markdown", [{"markdown_extensions": [{"attr_list": {}}]}], indirect=["ext_markdown"])
def test_backup_of_anchors(ext_markdown: Markdown) -> None:
"""Anchors with empty `href` are backed up."""
output = ext_markdown.convert("::: tests.fixtures.markdown_anchors")
# Anchors with id and no href have been backed up and updated.
_assert_contains_in_order(
[
'id="anchor"',
'id="tests.fixtures.markdown_anchors--anchor"',
'id="heading-anchor-1"',
'id="tests.fixtures.markdown_anchors--heading-anchor-1"',
'id="heading-anchor-2"',
'id="tests.fixtures.markdown_anchors--heading-anchor-2"',
'id="heading-anchor-3"',
'id="tests.fixtures.markdown_anchors--heading-anchor-3"',
],
output,
)
# Anchors with href and with or without id have been updated but not backed up.
_assert_contains_in_order(
[
'id="tests.fixtures.markdown_anchors--with-id"',
],
output,
)
assert 'id="with-id"' not in output
_assert_contains_in_order(
[
'href="#tests.fixtures.markdown_anchors--has-href1"',
'href="#tests.fixtures.markdown_anchors--has-href2"',
],
output,
)
assert 'href="#has-href1"' not in output
assert 'href="#has-href2"' not in output