markdown-exec 1.12.4__tar.gz → 1.12.5__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {markdown_exec-1.12.4 → markdown_exec-1.12.5}/CHANGELOG.md +8 -0
- {markdown_exec-1.12.4 → markdown_exec-1.12.5}/PKG-INFO +1 -1
- {markdown_exec-1.12.4 → markdown_exec-1.12.5}/pyproject.toml +1 -1
- {markdown_exec-1.12.4 → markdown_exec-1.12.5}/src/markdown_exec/_internal/mkdocs_plugin.py +1 -1
- {markdown_exec-1.12.4 → markdown_exec-1.12.5}/src/markdown_exec/_internal/processors.py +7 -1
- {markdown_exec-1.12.4 → markdown_exec-1.12.5}/src/markdown_exec/_internal/rendering.py +17 -2
- markdown_exec-1.12.5/tests/test_headings.py +122 -0
- {markdown_exec-1.12.4 → markdown_exec-1.12.5}/tests/test_toc.py +38 -0
- markdown_exec-1.12.4/tests/test_headings.py +0 -48
- {markdown_exec-1.12.4 → markdown_exec-1.12.5}/AI_POLICY.md +0 -0
- {markdown_exec-1.12.4 → markdown_exec-1.12.5}/CODE_OF_CONDUCT.md +0 -0
- {markdown_exec-1.12.4 → markdown_exec-1.12.5}/CONTRIBUTING.md +0 -0
- {markdown_exec-1.12.4 → markdown_exec-1.12.5}/LICENSE +0 -0
- {markdown_exec-1.12.4 → markdown_exec-1.12.5}/README.md +0 -0
- {markdown_exec-1.12.4 → markdown_exec-1.12.5}/config/coverage.ini +0 -0
- {markdown_exec-1.12.4 → markdown_exec-1.12.5}/config/git-changelog.toml +0 -0
- {markdown_exec-1.12.4 → markdown_exec-1.12.5}/config/pytest.ini +0 -0
- {markdown_exec-1.12.4 → markdown_exec-1.12.5}/config/ruff.toml +0 -0
- {markdown_exec-1.12.4 → markdown_exec-1.12.5}/config/ty.toml +0 -0
- {markdown_exec-1.12.4 → markdown_exec-1.12.5}/config/vscode/launch.json +0 -0
- {markdown_exec-1.12.4 → markdown_exec-1.12.5}/config/vscode/settings.json +0 -0
- {markdown_exec-1.12.4 → markdown_exec-1.12.5}/config/vscode/tasks.json +0 -0
- {markdown_exec-1.12.4 → markdown_exec-1.12.5}/config/zed/debug.json +0 -0
- {markdown_exec-1.12.4 → markdown_exec-1.12.5}/config/zed/settings.json +0 -0
- {markdown_exec-1.12.4 → markdown_exec-1.12.5}/config/zed/tasks.json +0 -0
- {markdown_exec-1.12.4 → markdown_exec-1.12.5}/docs/.overrides/main.html +0 -0
- {markdown_exec-1.12.4 → markdown_exec-1.12.5}/docs/.overrides/partials/comments.html +0 -0
- {markdown_exec-1.12.4 → markdown_exec-1.12.5}/docs/changelog.md +0 -0
- {markdown_exec-1.12.4 → markdown_exec-1.12.5}/docs/code_of_conduct.md +0 -0
- {markdown_exec-1.12.4 → markdown_exec-1.12.5}/docs/contributing.md +0 -0
- {markdown_exec-1.12.4 → markdown_exec-1.12.5}/docs/credits.md +0 -0
- {markdown_exec-1.12.4 → markdown_exec-1.12.5}/docs/css/apidocs.css +0 -0
- {markdown_exec-1.12.4 → markdown_exec-1.12.5}/docs/gallery.md +0 -0
- {markdown_exec-1.12.4 → markdown_exec-1.12.5}/docs/index.md +0 -0
- {markdown_exec-1.12.4 → markdown_exec-1.12.5}/docs/js/feedback.js +0 -0
- {markdown_exec-1.12.4 → markdown_exec-1.12.5}/docs/license.md +0 -0
- {markdown_exec-1.12.4 → markdown_exec-1.12.5}/docs/reference/api.md +0 -0
- {markdown_exec-1.12.4 → markdown_exec-1.12.5}/docs/schema.json +0 -0
- {markdown_exec-1.12.4 → markdown_exec-1.12.5}/docs/snippets/gallery/ansi.sh +0 -0
- {markdown_exec-1.12.4 → markdown_exec-1.12.5}/docs/snippets/gallery/argparse.py +0 -0
- {markdown_exec-1.12.4 → markdown_exec-1.12.5}/docs/snippets/gallery/argparse_format.py +0 -0
- {markdown_exec-1.12.4 → markdown_exec-1.12.5}/docs/snippets/gallery/chalk.py +0 -0
- {markdown_exec-1.12.4 → markdown_exec-1.12.5}/docs/snippets/gallery/d2.py +0 -0
- {markdown_exec-1.12.4 → markdown_exec-1.12.5}/docs/snippets/gallery/diagrams.py +0 -0
- {markdown_exec-1.12.4 → markdown_exec-1.12.5}/docs/snippets/gallery/drawsvg.py +0 -0
- {markdown_exec-1.12.4 → markdown_exec-1.12.5}/docs/snippets/gallery/expandable_filetree.py +0 -0
- {markdown_exec-1.12.4 → markdown_exec-1.12.5}/docs/snippets/gallery/hyperbolic.py +0 -0
- {markdown_exec-1.12.4 → markdown_exec-1.12.5}/docs/snippets/gallery/matplotlib.py +0 -0
- {markdown_exec-1.12.4 → markdown_exec-1.12.5}/docs/snippets/gallery/plotly.py +0 -0
- {markdown_exec-1.12.4 → markdown_exec-1.12.5}/docs/snippets/gallery/pydeps.py +0 -0
- {markdown_exec-1.12.4 → markdown_exec-1.12.5}/docs/snippets/gallery/qrcode.py +0 -0
- {markdown_exec-1.12.4 → markdown_exec-1.12.5}/docs/snippets/gallery/rich.py +0 -0
- {markdown_exec-1.12.4 → markdown_exec-1.12.5}/docs/snippets/gallery/rich_terminal.py +0 -0
- {markdown_exec-1.12.4 → markdown_exec-1.12.5}/docs/snippets/gallery/runpy.py +0 -0
- {markdown_exec-1.12.4 → markdown_exec-1.12.5}/docs/snippets/gallery/textual.py +0 -0
- {markdown_exec-1.12.4 → markdown_exec-1.12.5}/docs/snippets/usage/boolean_matrix.py +0 -0
- {markdown_exec-1.12.4 → markdown_exec-1.12.5}/docs/snippets/usage/hide.py +0 -0
- {markdown_exec-1.12.4 → markdown_exec-1.12.5}/docs/snippets/usage/multiple.pycon +0 -0
- {markdown_exec-1.12.4 → markdown_exec-1.12.5}/docs/snippets/usage/platform_html.py +0 -0
- {markdown_exec-1.12.4 → markdown_exec-1.12.5}/docs/snippets/usage/platform_md.py +0 -0
- {markdown_exec-1.12.4 → markdown_exec-1.12.5}/docs/snippets/usage/source.py +0 -0
- {markdown_exec-1.12.4 → markdown_exec-1.12.5}/docs/snippets/usage/source.pycon +0 -0
- {markdown_exec-1.12.4 → markdown_exec-1.12.5}/docs/usage/index.md +0 -0
- {markdown_exec-1.12.4 → markdown_exec-1.12.5}/docs/usage/pyodide.md +0 -0
- {markdown_exec-1.12.4 → markdown_exec-1.12.5}/docs/usage/python.md +0 -0
- {markdown_exec-1.12.4 → markdown_exec-1.12.5}/docs/usage/shell.md +0 -0
- {markdown_exec-1.12.4 → markdown_exec-1.12.5}/docs/usage/tree.md +0 -0
- {markdown_exec-1.12.4 → markdown_exec-1.12.5}/duties.py +0 -0
- {markdown_exec-1.12.4 → markdown_exec-1.12.5}/scripts/gen_credits.py +0 -0
- {markdown_exec-1.12.4 → markdown_exec-1.12.5}/scripts/get_version.py +0 -0
- {markdown_exec-1.12.4 → markdown_exec-1.12.5}/scripts/make +0 -0
- {markdown_exec-1.12.4 → markdown_exec-1.12.5}/scripts/make.py +0 -0
- {markdown_exec-1.12.4 → markdown_exec-1.12.5}/src/markdown_exec/__init__.py +0 -0
- {markdown_exec-1.12.4 → markdown_exec-1.12.5}/src/markdown_exec/_internal/__init__.py +0 -0
- {markdown_exec-1.12.4 → markdown_exec-1.12.5}/src/markdown_exec/_internal/debug.py +0 -0
- {markdown_exec-1.12.4 → markdown_exec-1.12.5}/src/markdown_exec/_internal/formatters/__init__.py +0 -0
- {markdown_exec-1.12.4 → markdown_exec-1.12.5}/src/markdown_exec/_internal/formatters/_exec_python.py +0 -0
- {markdown_exec-1.12.4 → markdown_exec-1.12.5}/src/markdown_exec/_internal/formatters/base.py +0 -0
- {markdown_exec-1.12.4 → markdown_exec-1.12.5}/src/markdown_exec/_internal/formatters/bash.py +0 -0
- {markdown_exec-1.12.4 → markdown_exec-1.12.5}/src/markdown_exec/_internal/formatters/console.py +0 -0
- {markdown_exec-1.12.4 → markdown_exec-1.12.5}/src/markdown_exec/_internal/formatters/markdown.py +0 -0
- {markdown_exec-1.12.4 → markdown_exec-1.12.5}/src/markdown_exec/_internal/formatters/pycon.py +0 -0
- {markdown_exec-1.12.4 → markdown_exec-1.12.5}/src/markdown_exec/_internal/formatters/pyodide.py +0 -0
- {markdown_exec-1.12.4 → markdown_exec-1.12.5}/src/markdown_exec/_internal/formatters/python.py +0 -0
- {markdown_exec-1.12.4 → markdown_exec-1.12.5}/src/markdown_exec/_internal/formatters/sh.py +0 -0
- {markdown_exec-1.12.4 → markdown_exec-1.12.5}/src/markdown_exec/_internal/formatters/tree.py +0 -0
- {markdown_exec-1.12.4 → markdown_exec-1.12.5}/src/markdown_exec/_internal/logger.py +0 -0
- {markdown_exec-1.12.4 → markdown_exec-1.12.5}/src/markdown_exec/_internal/main.py +0 -0
- {markdown_exec-1.12.4 → markdown_exec-1.12.5}/src/markdown_exec/assets/ansi.css +0 -0
- {markdown_exec-1.12.4 → markdown_exec-1.12.5}/src/markdown_exec/assets/pyodide.css +0 -0
- {markdown_exec-1.12.4 → markdown_exec-1.12.5}/src/markdown_exec/assets/pyodide.js +0 -0
- {markdown_exec-1.12.4 → markdown_exec-1.12.5}/src/markdown_exec/formatters/__init__.py +0 -0
- {markdown_exec-1.12.4 → markdown_exec-1.12.5}/src/markdown_exec/formatters/base.py +0 -0
- {markdown_exec-1.12.4 → markdown_exec-1.12.5}/src/markdown_exec/formatters/bash.py +0 -0
- {markdown_exec-1.12.4 → markdown_exec-1.12.5}/src/markdown_exec/formatters/console.py +0 -0
- {markdown_exec-1.12.4 → markdown_exec-1.12.5}/src/markdown_exec/formatters/markdown.py +0 -0
- {markdown_exec-1.12.4 → markdown_exec-1.12.5}/src/markdown_exec/formatters/pycon.py +0 -0
- {markdown_exec-1.12.4 → markdown_exec-1.12.5}/src/markdown_exec/formatters/pyodide.py +0 -0
- {markdown_exec-1.12.4 → markdown_exec-1.12.5}/src/markdown_exec/formatters/python.py +0 -0
- {markdown_exec-1.12.4 → markdown_exec-1.12.5}/src/markdown_exec/formatters/sh.py +0 -0
- {markdown_exec-1.12.4 → markdown_exec-1.12.5}/src/markdown_exec/formatters/tree.py +0 -0
- {markdown_exec-1.12.4 → markdown_exec-1.12.5}/src/markdown_exec/logger.py +0 -0
- {markdown_exec-1.12.4 → markdown_exec-1.12.5}/src/markdown_exec/mkdocs_plugin.py +0 -0
- {markdown_exec-1.12.4 → markdown_exec-1.12.5}/src/markdown_exec/processors.py +0 -0
- {markdown_exec-1.12.4 → markdown_exec-1.12.5}/src/markdown_exec/py.typed +0 -0
- {markdown_exec-1.12.4 → markdown_exec-1.12.5}/src/markdown_exec/rendering.py +0 -0
- {markdown_exec-1.12.4 → markdown_exec-1.12.5}/tests/__init__.py +0 -0
- {markdown_exec-1.12.4 → markdown_exec-1.12.5}/tests/conftest.py +0 -0
- {markdown_exec-1.12.4 → markdown_exec-1.12.5}/tests/test_api.py +0 -0
- {markdown_exec-1.12.4 → markdown_exec-1.12.5}/tests/test_base_formatter.py +0 -0
- {markdown_exec-1.12.4 → markdown_exec-1.12.5}/tests/test_converter.py +0 -0
- {markdown_exec-1.12.4 → markdown_exec-1.12.5}/tests/test_python.py +0 -0
- {markdown_exec-1.12.4 → markdown_exec-1.12.5}/tests/test_shell.py +0 -0
- {markdown_exec-1.12.4 → markdown_exec-1.12.5}/tests/test_tree.py +0 -0
- {markdown_exec-1.12.4 → markdown_exec-1.12.5}/tests/test_validator.py +0 -0
- {markdown_exec-1.12.4 → markdown_exec-1.12.5}/zensical.toml +0 -0
|
@@ -5,6 +5,14 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
|
|
|
5
5
|
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
|
|
6
6
|
|
|
7
7
|
<!-- insertion marker -->
|
|
8
|
+
## [1.12.5](https://github.com/pawamoy/markdown-exec/releases/tag/1.12.5) - 2026-10-14
|
|
9
|
+
|
|
10
|
+
<small>[Compare with 1.12.4](https://github.com/pawamoy/markdown-exec/compare/1.12.4...1.12.5)</small>
|
|
11
|
+
|
|
12
|
+
### Bug Fixes
|
|
13
|
+
|
|
14
|
+
- Preserve heading placeholders across Markdown conversions ([f071b31](https://github.com/pawamoy/markdown-exec/commit/f071b31c614fd008e8a88a417f9223d4a53ca051) by Timothée Mazzucotelli). [Issue-97](https://github.com/pawamoy/markdown-exec/issues/97)
|
|
15
|
+
|
|
8
16
|
## [1.12.4](https://github.com/pawamoy/markdown-exec/releases/tag/1.12.4) - 2026-10-06
|
|
9
17
|
|
|
10
18
|
<small>[Compare with 1.12.3](https://github.com/pawamoy/markdown-exec/compare/1.12.3...1.12.4)</small>
|
|
@@ -150,7 +150,7 @@ class MarkdownExecPlugin(BasePlugin[MarkdownExecPluginConfig]):
|
|
|
150
150
|
|
|
151
151
|
def _add_asset(self, config: MkDocsConfig, asset_file: str, asset_type: str) -> None:
|
|
152
152
|
asset_filename = f"assets/_markdown_exec_{asset_file}"
|
|
153
|
-
asset_content = Path(__file__).parent.parent.joinpath("assets", asset_file).read_text()
|
|
153
|
+
asset_content = Path(__file__).parent.parent.joinpath("assets", asset_file).read_text(encoding="utf8")
|
|
154
154
|
write_file(asset_content.encode("utf-8"), os.path.join(config.site_dir, asset_filename)) # noqa: PTH118
|
|
155
155
|
config[f"extra_{asset_type}"].insert(0, asset_filename)
|
|
156
156
|
|
|
@@ -87,7 +87,7 @@ class HeadingReportingTreeprocessor(Treeprocessor):
|
|
|
87
87
|
"""Run the treeprocessor."""
|
|
88
88
|
for el in root.iter():
|
|
89
89
|
if self.regex.fullmatch(el.tag):
|
|
90
|
-
el = copy.
|
|
90
|
+
el = copy.deepcopy(el) # noqa: PLW2901
|
|
91
91
|
# 'toc' extension's first pass (which we require to build heading stubs/ids) also edits the HTML.
|
|
92
92
|
# Undo the permalink edit so we can pass this heading to the outer pass of the 'toc' extension.
|
|
93
93
|
if len(el) > 0 and el[-1].get("class") == self.md.treeprocessors["toc"].permalink_class: # ty:ignore[unresolved-attribute]
|
|
@@ -117,9 +117,15 @@ class InsertHeadings(Treeprocessor):
|
|
|
117
117
|
return
|
|
118
118
|
|
|
119
119
|
for el in root.iter():
|
|
120
|
+
# Only block containers hold generated output. Heading content can use another Markdown instance's stash.
|
|
121
|
+
if not self.md.is_block_level(el.tag) or HeadingReportingTreeprocessor.regex.fullmatch(el.tag):
|
|
122
|
+
continue
|
|
123
|
+
|
|
120
124
|
match = HTML_PLACEHOLDER_RE.match(el.text or "")
|
|
121
125
|
if match:
|
|
122
126
|
counter = int(match.group(1))
|
|
127
|
+
if counter >= len(self.md.htmlStash.rawHtmlBlocks):
|
|
128
|
+
continue
|
|
123
129
|
markup: Markup = self.md.htmlStash.rawHtmlBlocks[counter] # ty:ignore[invalid-assignment]
|
|
124
130
|
if headings := self.headings.get(markup):
|
|
125
131
|
div = Element("div", {"class": "markdown-exec"})
|
|
@@ -27,6 +27,7 @@ from typing import TYPE_CHECKING, Any
|
|
|
27
27
|
from warnings import warn
|
|
28
28
|
|
|
29
29
|
from markdown import Markdown
|
|
30
|
+
from markdown.util import HTML_PLACEHOLDER_RE
|
|
30
31
|
from markupsafe import Markup
|
|
31
32
|
|
|
32
33
|
from markdown_exec._internal.processors import (
|
|
@@ -37,6 +38,7 @@ from markdown_exec._internal.processors import (
|
|
|
37
38
|
)
|
|
38
39
|
|
|
39
40
|
if TYPE_CHECKING:
|
|
41
|
+
import re
|
|
40
42
|
from collections.abc import Iterator
|
|
41
43
|
from xml.etree.ElementTree import Element
|
|
42
44
|
|
|
@@ -275,7 +277,20 @@ class MarkdownConverter:
|
|
|
275
277
|
def _original_md(self) -> Markdown:
|
|
276
278
|
return getattr(self._md_ref, "_original_md", self._md_ref)
|
|
277
279
|
|
|
278
|
-
def _report_headings(self, markup: Markup) -> None:
|
|
280
|
+
def _report_headings(self, markup: Markup, md: Markdown) -> None:
|
|
281
|
+
def restash(match: re.Match[str]) -> str:
|
|
282
|
+
html = md.postprocessors["raw_html"].run(match.group(0))
|
|
283
|
+
return self._original_md.htmlStash.store(html)
|
|
284
|
+
|
|
285
|
+
# Resolve placeholders in their own stash before passing heading copies to the outer conversion.
|
|
286
|
+
for heading in self._headings:
|
|
287
|
+
for element in heading.iter():
|
|
288
|
+
# Preserve AtomicString values so inline processing does not reinterpret code.
|
|
289
|
+
if element.text:
|
|
290
|
+
element.text = type(element.text)(HTML_PLACEHOLDER_RE.sub(restash, element.text))
|
|
291
|
+
if element.tail:
|
|
292
|
+
element.tail = type(element.tail)(HTML_PLACEHOLDER_RE.sub(restash, element.tail))
|
|
293
|
+
|
|
279
294
|
self._original_md.treeprocessors[InsertHeadings.name].headings[markup] = self._headings # ty:ignore[unresolved-attribute]
|
|
280
295
|
self._headings = []
|
|
281
296
|
|
|
@@ -303,6 +318,6 @@ class MarkdownConverter:
|
|
|
303
318
|
|
|
304
319
|
# pass headings to upstream conversion layer
|
|
305
320
|
if self._update_toc:
|
|
306
|
-
self._report_headings(markup)
|
|
321
|
+
self._report_headings(markup, md)
|
|
307
322
|
|
|
308
323
|
return markup
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
# SPDX-License-Identifier: ISC
|
|
2
|
+
#
|
|
3
|
+
# ISC License
|
|
4
|
+
#
|
|
5
|
+
# Copyright (c) 2022, Timothée Mazzucotelli and contributors
|
|
6
|
+
#
|
|
7
|
+
# Permission to use, copy, modify, and/or distribute this software for any
|
|
8
|
+
# purpose with or without fee is hereby granted, provided that the above
|
|
9
|
+
# copyright notice and this permission notice appear in all copies.
|
|
10
|
+
#
|
|
11
|
+
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
12
|
+
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
13
|
+
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
14
|
+
# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
15
|
+
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
16
|
+
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
|
17
|
+
# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
18
|
+
|
|
19
|
+
"""Tests for headings."""
|
|
20
|
+
|
|
21
|
+
from __future__ import annotations
|
|
22
|
+
|
|
23
|
+
from textwrap import dedent
|
|
24
|
+
from typing import TYPE_CHECKING
|
|
25
|
+
|
|
26
|
+
import pytest
|
|
27
|
+
from mkdocs.commands.build import build
|
|
28
|
+
from mkdocs.config import load_config
|
|
29
|
+
|
|
30
|
+
from markdown_exec import markdown_config
|
|
31
|
+
|
|
32
|
+
if TYPE_CHECKING:
|
|
33
|
+
from pathlib import Path
|
|
34
|
+
|
|
35
|
+
from markdown import Markdown
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
def test_headings_removal(md: Markdown) -> None:
|
|
39
|
+
"""Headings should leave no trace behind.
|
|
40
|
+
|
|
41
|
+
Parameters:
|
|
42
|
+
md: A Markdown instance (fixture).
|
|
43
|
+
"""
|
|
44
|
+
html = md.convert(
|
|
45
|
+
dedent(
|
|
46
|
+
"""
|
|
47
|
+
=== "File layout"
|
|
48
|
+
|
|
49
|
+
```tree
|
|
50
|
+
./
|
|
51
|
+
hello.md
|
|
52
|
+
```
|
|
53
|
+
""",
|
|
54
|
+
),
|
|
55
|
+
)
|
|
56
|
+
assert 'class="markdown-exec"' not in html
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
@pytest.mark.parametrize("exec_first", [True, False])
|
|
60
|
+
def test_exec_block_with_mkdocstrings_headings(
|
|
61
|
+
tmp_path: Path,
|
|
62
|
+
monkeypatch: pytest.MonkeyPatch,
|
|
63
|
+
exec_first: bool,
|
|
64
|
+
) -> None:
|
|
65
|
+
"""Build a page with an executed block and docstring headings containing inline code."""
|
|
66
|
+
# Keep the plugin's saved configuration local to this build.
|
|
67
|
+
monkeypatch.setattr(markdown_config, "exts", None)
|
|
68
|
+
monkeypatch.setattr(markdown_config, "exts_config", None)
|
|
69
|
+
|
|
70
|
+
config_file = tmp_path / "mkdocs.yml"
|
|
71
|
+
config_file.write_text("site_name: Heading reproduction\n", encoding="utf-8")
|
|
72
|
+
docs_dir = tmp_path / "docs"
|
|
73
|
+
docs_dir.mkdir()
|
|
74
|
+
|
|
75
|
+
# Four headings reproduce the invalid stash indices without a large package.
|
|
76
|
+
(tmp_path / "repro97.py").write_text(
|
|
77
|
+
dedent(
|
|
78
|
+
'''\
|
|
79
|
+
"""Summary.
|
|
80
|
+
|
|
81
|
+
# Heading `1`
|
|
82
|
+
|
|
83
|
+
Text with `code`.
|
|
84
|
+
|
|
85
|
+
# Heading `2`
|
|
86
|
+
|
|
87
|
+
Text with `code again`.
|
|
88
|
+
|
|
89
|
+
# Heading `3`
|
|
90
|
+
|
|
91
|
+
Text with `code again and again`.
|
|
92
|
+
|
|
93
|
+
# Heading `4`.
|
|
94
|
+
|
|
95
|
+
Text with `code again and again again`.
|
|
96
|
+
"""
|
|
97
|
+
''',
|
|
98
|
+
),
|
|
99
|
+
encoding="utf-8",
|
|
100
|
+
)
|
|
101
|
+
exec_block = '```python exec="1"\nprint("hello from the exec block")\n```'
|
|
102
|
+
directive = "::: repro97"
|
|
103
|
+
blocks = [exec_block, directive] if exec_first else [directive, exec_block]
|
|
104
|
+
(docs_dir / "index.md").write_text("\n\n".join(blocks), encoding="utf-8")
|
|
105
|
+
config = load_config(
|
|
106
|
+
config_file=str(config_file),
|
|
107
|
+
docs_dir=str(docs_dir),
|
|
108
|
+
site_dir=str(tmp_path / "site"),
|
|
109
|
+
plugins=[
|
|
110
|
+
"markdown-exec",
|
|
111
|
+
{"mkdocstrings": {"handlers": {"python": {"paths": [str(tmp_path)], "options": {"show_source": False}}}}},
|
|
112
|
+
],
|
|
113
|
+
markdown_extensions=["toc", "pymdownx.superfences"],
|
|
114
|
+
)
|
|
115
|
+
|
|
116
|
+
build(config)
|
|
117
|
+
|
|
118
|
+
# Both parts of the page render successfully, in either order.
|
|
119
|
+
html = (tmp_path / "site" / "index.html").read_text(encoding="utf-8")
|
|
120
|
+
assert "hello from the exec block" in html
|
|
121
|
+
assert "Heading <code>1</code>" in html
|
|
122
|
+
assert "Heading <code>4</code>." in html
|
|
@@ -23,6 +23,7 @@ from __future__ import annotations
|
|
|
23
23
|
from textwrap import dedent
|
|
24
24
|
from typing import TYPE_CHECKING
|
|
25
25
|
|
|
26
|
+
import pytest
|
|
26
27
|
from markdown.extensions.toc import TocExtension
|
|
27
28
|
|
|
28
29
|
if TYPE_CHECKING:
|
|
@@ -105,3 +106,40 @@ def test_both_updating_and_not_updating_toc(md: Markdown) -> None:
|
|
|
105
106
|
assert "medium-heading" in md.toc # ty:ignore[unresolved-attribute]
|
|
106
107
|
assert "small-heading" not in md.toc # ty:ignore[unresolved-attribute]
|
|
107
108
|
assert "tiny-heading" in md.toc # ty:ignore[unresolved-attribute]
|
|
109
|
+
|
|
110
|
+
|
|
111
|
+
@pytest.mark.parametrize(
|
|
112
|
+
("heading", "expected_name", "expected_html"),
|
|
113
|
+
[
|
|
114
|
+
("Heading —", "Heading —", "Heading —"),
|
|
115
|
+
(
|
|
116
|
+
"Heading **—** tail ©",
|
|
117
|
+
"Heading — tail ©",
|
|
118
|
+
"Heading <strong>—</strong> tail ©",
|
|
119
|
+
),
|
|
120
|
+
("Heading <span>inline</span>", "Heading inline", "Heading <span>inline</span>"),
|
|
121
|
+
("Heading `*code*`", "Heading *code*", "Heading <code>*code*</code>"),
|
|
122
|
+
("—", "—", "—"),
|
|
123
|
+
],
|
|
124
|
+
)
|
|
125
|
+
def test_generated_headings_keep_stashed_content(
|
|
126
|
+
md: Markdown,
|
|
127
|
+
heading: str,
|
|
128
|
+
expected_name: str,
|
|
129
|
+
expected_html: str,
|
|
130
|
+
) -> None:
|
|
131
|
+
"""Keep heading content when the inner and outer HTML stashes use the same IDs."""
|
|
132
|
+
TocExtension(permalink=True).extendMarkdown(md)
|
|
133
|
+
|
|
134
|
+
# Entities and inline HTML belong to the generated block's Markdown instance.
|
|
135
|
+
source = f'```md exec="1" idprefix=""\n# {heading}\n```'
|
|
136
|
+
|
|
137
|
+
html = md.convert(source)
|
|
138
|
+
|
|
139
|
+
# The page keeps the rendered heading, and its ToC uses the same content.
|
|
140
|
+
assert '<h1 id="' in html
|
|
141
|
+
assert expected_html in html
|
|
142
|
+
assert md.toc_tokens[0]["name"] == expected_name # ty:ignore[unresolved-attribute]
|
|
143
|
+
assert md.toc_tokens[0]["html"] == expected_html # ty:ignore[unresolved-attribute]
|
|
144
|
+
assert expected_name in md.toc # ty:ignore[unresolved-attribute]
|
|
145
|
+
assert "wzxhzdk" not in html
|
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
# SPDX-License-Identifier: ISC
|
|
2
|
-
#
|
|
3
|
-
# ISC License
|
|
4
|
-
#
|
|
5
|
-
# Copyright (c) 2022, Timothée Mazzucotelli and contributors
|
|
6
|
-
#
|
|
7
|
-
# Permission to use, copy, modify, and/or distribute this software for any
|
|
8
|
-
# purpose with or without fee is hereby granted, provided that the above
|
|
9
|
-
# copyright notice and this permission notice appear in all copies.
|
|
10
|
-
#
|
|
11
|
-
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
12
|
-
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
13
|
-
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
14
|
-
# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
15
|
-
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
16
|
-
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
|
17
|
-
# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
18
|
-
|
|
19
|
-
"""Tests for headings."""
|
|
20
|
-
|
|
21
|
-
from __future__ import annotations
|
|
22
|
-
|
|
23
|
-
from textwrap import dedent
|
|
24
|
-
from typing import TYPE_CHECKING
|
|
25
|
-
|
|
26
|
-
if TYPE_CHECKING:
|
|
27
|
-
from markdown import Markdown
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
def test_headings_removal(md: Markdown) -> None:
|
|
31
|
-
"""Headings should leave no trace behind.
|
|
32
|
-
|
|
33
|
-
Parameters:
|
|
34
|
-
md: A Markdown instance (fixture).
|
|
35
|
-
"""
|
|
36
|
-
html = md.convert(
|
|
37
|
-
dedent(
|
|
38
|
-
"""
|
|
39
|
-
=== "File layout"
|
|
40
|
-
|
|
41
|
-
```tree
|
|
42
|
-
./
|
|
43
|
-
hello.md
|
|
44
|
-
```
|
|
45
|
-
""",
|
|
46
|
-
),
|
|
47
|
-
)
|
|
48
|
-
assert 'class="markdown-exec"' not in html
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{markdown_exec-1.12.4 → markdown_exec-1.12.5}/src/markdown_exec/_internal/formatters/__init__.py
RENAMED
|
File without changes
|
{markdown_exec-1.12.4 → markdown_exec-1.12.5}/src/markdown_exec/_internal/formatters/_exec_python.py
RENAMED
|
File without changes
|
{markdown_exec-1.12.4 → markdown_exec-1.12.5}/src/markdown_exec/_internal/formatters/base.py
RENAMED
|
File without changes
|
{markdown_exec-1.12.4 → markdown_exec-1.12.5}/src/markdown_exec/_internal/formatters/bash.py
RENAMED
|
File without changes
|
{markdown_exec-1.12.4 → markdown_exec-1.12.5}/src/markdown_exec/_internal/formatters/console.py
RENAMED
|
File without changes
|
{markdown_exec-1.12.4 → markdown_exec-1.12.5}/src/markdown_exec/_internal/formatters/markdown.py
RENAMED
|
File without changes
|
{markdown_exec-1.12.4 → markdown_exec-1.12.5}/src/markdown_exec/_internal/formatters/pycon.py
RENAMED
|
File without changes
|
{markdown_exec-1.12.4 → markdown_exec-1.12.5}/src/markdown_exec/_internal/formatters/pyodide.py
RENAMED
|
File without changes
|
{markdown_exec-1.12.4 → markdown_exec-1.12.5}/src/markdown_exec/_internal/formatters/python.py
RENAMED
|
File without changes
|
|
File without changes
|
{markdown_exec-1.12.4 → markdown_exec-1.12.5}/src/markdown_exec/_internal/formatters/tree.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|