mdformat-mkdocs 5.1.5b0__tar.gz → 5.2.0b0__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.
Files changed (27) hide show
  1. {mdformat_mkdocs-5.1.5b0 → mdformat_mkdocs-5.2.0b0}/PKG-INFO +3 -1
  2. {mdformat_mkdocs-5.1.5b0 → mdformat_mkdocs-5.2.0b0}/README.md +2 -0
  3. {mdformat_mkdocs-5.1.5b0 → mdformat_mkdocs-5.2.0b0}/mdformat_mkdocs/__init__.py +1 -1
  4. {mdformat_mkdocs-5.1.5b0 → mdformat_mkdocs-5.2.0b0}/mdformat_mkdocs/mdit_plugins/__init__.py +6 -0
  5. mdformat_mkdocs-5.2.0b0/mdformat_mkdocs/mdit_plugins/_mkdocstrings_injection.py +74 -0
  6. {mdformat_mkdocs-5.1.5b0 → mdformat_mkdocs-5.2.0b0}/mdformat_mkdocs/plugin.py +39 -3
  7. {mdformat_mkdocs-5.1.5b0 → mdformat_mkdocs-5.2.0b0}/pyproject.toml +2 -2
  8. {mdformat_mkdocs-5.1.5b0 → mdformat_mkdocs-5.2.0b0}/LICENSE +0 -0
  9. {mdformat_mkdocs-5.1.5b0 → mdformat_mkdocs-5.2.0b0}/mdformat_mkdocs/_helpers.py +0 -0
  10. {mdformat_mkdocs-5.1.5b0 → mdformat_mkdocs-5.2.0b0}/mdformat_mkdocs/_normalize_list.py +0 -0
  11. {mdformat_mkdocs-5.1.5b0 → mdformat_mkdocs-5.2.0b0}/mdformat_mkdocs/_postprocess_inline.py +0 -0
  12. {mdformat_mkdocs-5.1.5b0 → mdformat_mkdocs-5.2.0b0}/mdformat_mkdocs/_synced/__init__.py +0 -0
  13. {mdformat_mkdocs-5.1.5b0 → mdformat_mkdocs-5.2.0b0}/mdformat_mkdocs/_synced/admon_factories/README.md +0 -0
  14. {mdformat_mkdocs-5.1.5b0 → mdformat_mkdocs-5.2.0b0}/mdformat_mkdocs/_synced/admon_factories/__init__.py +0 -0
  15. {mdformat_mkdocs-5.1.5b0 → mdformat_mkdocs-5.2.0b0}/mdformat_mkdocs/_synced/admon_factories/_whitespace_admon_factories.py +0 -0
  16. {mdformat_mkdocs-5.1.5b0 → mdformat_mkdocs-5.2.0b0}/mdformat_mkdocs/mdit_plugins/_material_admon.py +0 -0
  17. {mdformat_mkdocs-5.1.5b0 → mdformat_mkdocs-5.2.0b0}/mdformat_mkdocs/mdit_plugins/_material_content_tabs.py +0 -0
  18. {mdformat_mkdocs-5.1.5b0 → mdformat_mkdocs-5.2.0b0}/mdformat_mkdocs/mdit_plugins/_material_deflist.py +0 -0
  19. {mdformat_mkdocs-5.1.5b0 → mdformat_mkdocs-5.2.0b0}/mdformat_mkdocs/mdit_plugins/_mkdocstrings_autorefs.py +0 -0
  20. {mdformat_mkdocs-5.1.5b0 → mdformat_mkdocs-5.2.0b0}/mdformat_mkdocs/mdit_plugins/_mkdocstrings_crossreference.py +0 -0
  21. {mdformat_mkdocs-5.1.5b0 → mdformat_mkdocs-5.2.0b0}/mdformat_mkdocs/mdit_plugins/_pymd_abbreviations.py +0 -0
  22. {mdformat_mkdocs-5.1.5b0 → mdformat_mkdocs-5.2.0b0}/mdformat_mkdocs/mdit_plugins/_pymd_admon.py +0 -0
  23. {mdformat_mkdocs-5.1.5b0 → mdformat_mkdocs-5.2.0b0}/mdformat_mkdocs/mdit_plugins/_pymd_arithmatex.py +0 -0
  24. {mdformat_mkdocs-5.1.5b0 → mdformat_mkdocs-5.2.0b0}/mdformat_mkdocs/mdit_plugins/_pymd_captions.py +0 -0
  25. {mdformat_mkdocs-5.1.5b0 → mdformat_mkdocs-5.2.0b0}/mdformat_mkdocs/mdit_plugins/_pymd_snippet.py +0 -0
  26. {mdformat_mkdocs-5.1.5b0 → mdformat_mkdocs-5.2.0b0}/mdformat_mkdocs/mdit_plugins/_python_markdown_attr_list.py +0 -0
  27. {mdformat_mkdocs-5.1.5b0 → mdformat_mkdocs-5.2.0b0}/mdformat_mkdocs/py.typed +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: mdformat_mkdocs
3
- Version: 5.1.5b0
3
+ Version: 5.2.0b0
4
4
  Summary: An mdformat plugin for mkdocs and Material for MkDocs
5
5
  Keywords: markdown,markdown-it,mdformat,mdformat_plugin_template
6
6
  Author: kyleking
@@ -62,6 +62,8 @@ Supports:
62
62
  - [MkDocs-Material Content Tabs\*](https://squidfunk.github.io/mkdocs-material/reference/content-tabs)
63
63
  - \*Note: the markup (HTML) rendered by this plugin is sufficient for formatting but not for viewing in a browser. Please open an issue if you have a need to generate valid HTML.
64
64
  - [MkDocs-Material Definition Lists](https://squidfunk.github.io/mkdocs-material/reference/lists/#using-definition-lists)
65
+ - [mkdocstrings Injection Blocks](https://mkdocstrings.github.io/usage/)
66
+ - Preserves `:::` identifier blocks and their indented YAML options verbatim
65
67
  - [mkdocstrings Anchors (autorefs)](https://mkdocstrings.github.io/autorefs/#markdown-anchors)
66
68
  - [mkdocstrings Cross-References](https://mkdocstrings.github.io/usage/#cross-references)
67
69
  - [Python Markdown "Abbreviations"\*](https://squidfunk.github.io/mkdocs-material/reference/tooltips/#adding-abbreviations)
@@ -15,6 +15,8 @@ Supports:
15
15
  - [MkDocs-Material Content Tabs\*](https://squidfunk.github.io/mkdocs-material/reference/content-tabs)
16
16
  - \*Note: the markup (HTML) rendered by this plugin is sufficient for formatting but not for viewing in a browser. Please open an issue if you have a need to generate valid HTML.
17
17
  - [MkDocs-Material Definition Lists](https://squidfunk.github.io/mkdocs-material/reference/lists/#using-definition-lists)
18
+ - [mkdocstrings Injection Blocks](https://mkdocstrings.github.io/usage/)
19
+ - Preserves `:::` identifier blocks and their indented YAML options verbatim
18
20
  - [mkdocstrings Anchors (autorefs)](https://mkdocstrings.github.io/autorefs/#markdown-anchors)
19
21
  - [mkdocstrings Cross-References](https://mkdocstrings.github.io/usage/#cross-references)
20
22
  - [Python Markdown "Abbreviations"\*](https://squidfunk.github.io/mkdocs-material/reference/tooltips/#adding-abbreviations)
@@ -1,7 +1,7 @@
1
1
  # ruff: noqa: RUF067
2
2
  """An mdformat plugin for `mkdocs`."""
3
3
 
4
- __version__ = "5.1.5b0"
4
+ __version__ = "5.2.0b0"
5
5
 
6
6
  __plugin_name__ = "mkdocs"
7
7
 
@@ -21,6 +21,10 @@ from ._mkdocstrings_crossreference import (
21
21
  MKDOCSTRINGS_CROSSREFERENCE_PREFIX,
22
22
  mkdocstrings_crossreference_plugin,
23
23
  )
24
+ from ._mkdocstrings_injection import (
25
+ MKDOCSTRINGS_INJECTION_PREFIX,
26
+ mkdocstrings_injection_plugin,
27
+ )
24
28
  from ._pymd_abbreviations import PYMD_ABBREVIATIONS_PREFIX, pymd_abbreviations_plugin
25
29
  from ._pymd_admon import pymd_admon_plugin
26
30
  from ._pymd_arithmatex import (
@@ -48,6 +52,7 @@ __all__ = (
48
52
  "MKDOCSTRINGS_AUTOREFS_PREFIX",
49
53
  "MKDOCSTRINGS_CROSSREFERENCE_PREFIX",
50
54
  "MKDOCSTRINGS_HEADING_AUTOREFS_PREFIX",
55
+ "MKDOCSTRINGS_INJECTION_PREFIX",
51
56
  "PYMD_ABBREVIATIONS_PREFIX",
52
57
  "PYMD_CAPTIONS_PREFIX",
53
58
  "PYMD_SNIPPET_PREFIX",
@@ -59,6 +64,7 @@ __all__ = (
59
64
  "material_deflist_plugin",
60
65
  "mkdocstrings_autorefs_plugin",
61
66
  "mkdocstrings_crossreference_plugin",
67
+ "mkdocstrings_injection_plugin",
62
68
  "pymd_abbreviations_plugin",
63
69
  "pymd_admon_plugin",
64
70
  "pymd_arithmatex_plugin",
@@ -0,0 +1,74 @@
1
+ """mkdocstrings injection blocks.
2
+
3
+ Matches:
4
+
5
+ ```md
6
+ ::: package.module.Class
7
+ options:
8
+ heading_level: 2
9
+ ```
10
+
11
+ Docs: https://mkdocstrings.github.io/usage/
12
+
13
+ """
14
+
15
+ from __future__ import annotations
16
+
17
+ import re
18
+ from typing import TYPE_CHECKING
19
+
20
+ from mdit_py_plugins.utils import is_code_block
21
+
22
+ if TYPE_CHECKING:
23
+ from markdown_it import MarkdownIt
24
+ from markdown_it.rules_block import StateBlock
25
+
26
+ _INJECTION_PATTERN = re.compile(r"^:::\s+\S")
27
+ MKDOCSTRINGS_INJECTION_PREFIX = "mkdocstrings_injection"
28
+
29
+
30
+ def _get_line(state: StateBlock, line: int, base_indent: int) -> str:
31
+ return state.src[state.bMarks[line] + base_indent : state.eMarks[line]]
32
+
33
+
34
+ def _mkdocstrings_injection(
35
+ state: StateBlock,
36
+ start_line: int,
37
+ end_line: int,
38
+ silent: bool,
39
+ ) -> bool:
40
+ if is_code_block(state, start_line):
41
+ return False
42
+
43
+ base_indent = state.blkIndent
44
+ header = _get_line(state, start_line, base_indent)
45
+ if not _INJECTION_PATTERN.match(header):
46
+ return False
47
+
48
+ if silent:
49
+ return True
50
+
51
+ lines = [header]
52
+ next_line = start_line + 1
53
+ while next_line < end_line:
54
+ if state.tShift[next_line] <= base_indent:
55
+ break
56
+ lines.append(_get_line(state, next_line, base_indent))
57
+ next_line += 1
58
+
59
+ token = state.push(MKDOCSTRINGS_INJECTION_PREFIX, "", 0)
60
+ token.content = "\n".join(lines)
61
+ token.block = True
62
+ token.map = [start_line, next_line]
63
+
64
+ state.line = next_line
65
+ return True
66
+
67
+
68
+ def mkdocstrings_injection_plugin(md: MarkdownIt) -> None:
69
+ md.block.ruler.before(
70
+ "paragraph",
71
+ MKDOCSTRINGS_INJECTION_PREFIX,
72
+ _mkdocstrings_injection,
73
+ {"alt": ["paragraph"]},
74
+ )
@@ -20,6 +20,7 @@ from .mdit_plugins import (
20
20
  MKDOCSTRINGS_AUTOREFS_PREFIX,
21
21
  MKDOCSTRINGS_CROSSREFERENCE_PREFIX,
22
22
  MKDOCSTRINGS_HEADING_AUTOREFS_PREFIX,
23
+ MKDOCSTRINGS_INJECTION_PREFIX,
23
24
  PYMD_ABBREVIATIONS_PREFIX,
24
25
  PYMD_CAPTIONS_PREFIX,
25
26
  PYMD_SNIPPET_PREFIX,
@@ -31,6 +32,7 @@ from .mdit_plugins import (
31
32
  material_deflist_plugin,
32
33
  mkdocstrings_autorefs_plugin,
33
34
  mkdocstrings_crossreference_plugin,
35
+ mkdocstrings_injection_plugin,
34
36
  pymd_abbreviations_plugin,
35
37
  pymd_admon_plugin,
36
38
  pymd_arithmatex_plugin,
@@ -109,6 +111,7 @@ def update_mdit(mdit: MarkdownIt) -> None:
109
111
  mdit.use(material_content_tabs_plugin)
110
112
  mdit.use(material_deflist_plugin)
111
113
  mdit.use(mkdocstrings_autorefs_plugin)
114
+ mdit.use(mkdocstrings_injection_plugin)
112
115
  mdit.use(pymd_abbreviations_plugin)
113
116
  mdit.use(pymd_admon_plugin)
114
117
  mdit.use(pymd_snippet_plugin)
@@ -190,6 +193,29 @@ def _render_inline_content(node: RenderTreeNode, context: RenderContext) -> str:
190
193
  return inline.content
191
194
 
192
195
 
196
+ _ESCAPED_LINK_SPACED_URL = re.compile(r"\\\[([^\]]*)\\\]\(([^)]*[ ][^)]*)\)")
197
+
198
+
199
+ def _fix_links_with_spaced_urls(
200
+ text: str,
201
+ node: RenderTreeNode, # noqa: ARG001
202
+ context: RenderContext, # noqa: ARG001
203
+ ) -> str:
204
+ """Rewrite escaped links with space-containing URLs to angle-bracket syntax.
205
+
206
+ CommonMark requires link destinations with spaces to use angle brackets.
207
+ When markdown-it fails to parse [text](url with space) as a link, mdformat
208
+ escapes the brackets. Detects and repairs those cases.
209
+
210
+ Addresses: https://github.com/KyleKing/mdformat-mkdocs/issues/80
211
+
212
+ """
213
+ return _ESCAPED_LINK_SPACED_URL.sub(
214
+ lambda m: f"[{m.group(1)}](<{m.group(2)}>)",
215
+ text,
216
+ )
217
+
218
+
193
219
  def _render_text(node: RenderTreeNode, context: RenderContext) -> str:
194
220
  r"""Re-escape dollar signs that mdformat core stripped.
195
221
 
@@ -327,6 +353,7 @@ RENDERERS: Mapping[str, Render] = {
327
353
  PYMD_CAPTIONS_PREFIX: render_pymd_caption,
328
354
  MKDOCSTRINGS_AUTOREFS_PREFIX: _render_meta_content,
329
355
  MKDOCSTRINGS_CROSSREFERENCE_PREFIX: _render_cross_reference,
356
+ MKDOCSTRINGS_INJECTION_PREFIX: _render_node_content,
330
357
  MKDOCSTRINGS_HEADING_AUTOREFS_PREFIX: _render_heading_autoref,
331
358
  PYMD_ABBREVIATIONS_PREFIX: _render_inline_content,
332
359
  PYMD_SNIPPET_PREFIX: _render_inline_content,
@@ -336,13 +363,22 @@ RENDERERS: Mapping[str, Render] = {
336
363
 
337
364
  if TYPE_CHECKING:
338
365
  normalize_list: Postprocess
339
- postprocess_list_wrap: Postprocess
366
+ postprocess_inline: Postprocess
340
367
  else:
341
368
  normalize_list = partial(
342
369
  unbounded_normalize_list,
343
370
  check_if_align_semantic_breaks_in_lists=cli_is_align_semantic_breaks_in_lists,
344
371
  )
345
- postprocess_list_wrap = _postprocess_list_wrap
372
+
373
+ def postprocess_inline(
374
+ text: str,
375
+ node: RenderTreeNode,
376
+ context: RenderContext,
377
+ ) -> str:
378
+ """Run all inline postprocessors in sequence."""
379
+ text = _postprocess_list_wrap(text, node, context)
380
+ return _fix_links_with_spaced_urls(text, node, context)
381
+
346
382
 
347
383
  # A mapping from `RenderTreeNode.type` to a `Postprocess` that does
348
384
  # postprocessing for the output of the `Render` function. Unlike
@@ -351,7 +387,7 @@ else:
351
387
  # will run in series.
352
388
  POSTPROCESSORS: Mapping[str, Postprocess] = {
353
389
  "bullet_list": normalize_list,
354
- "inline": postprocess_list_wrap,
390
+ "inline": postprocess_inline,
355
391
  "ordered_list": normalize_list,
356
392
  "paragraph": escape_deflist,
357
393
  }
@@ -25,7 +25,7 @@ license-files = ["LICENSE"]
25
25
  name = "mdformat_mkdocs"
26
26
  readme = "README.md"
27
27
  requires-python = ">=3.10.0"
28
- version = "5.1.5b0"
28
+ version = "5.2.0b0"
29
29
 
30
30
  [project.entry-points."mdformat.parser_extension"]
31
31
  mkdocs = "mdformat_mkdocs"
@@ -69,7 +69,7 @@ homepage = "https://github.com/kyleking/mdformat-mkdocs"
69
69
 
70
70
  [tool.commitizen]
71
71
  tag_format = "v${version}"
72
- version = "5.1.5b0"
72
+ version = "5.2.0b0"
73
73
  version_files = ["mdformat_mkdocs/__init__.py", "pyproject.toml:^version"]
74
74
 
75
75
  [tool.mypy]