mdformat-mkdocs 5.2.0b1__tar.gz → 5.2.0b2__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.2.0b1 → mdformat_mkdocs-5.2.0b2}/PKG-INFO +1 -1
  2. {mdformat_mkdocs-5.2.0b1 → mdformat_mkdocs-5.2.0b2}/mdformat_mkdocs/__init__.py +1 -1
  3. {mdformat_mkdocs-5.2.0b1 → mdformat_mkdocs-5.2.0b2}/mdformat_mkdocs/plugin.py +29 -5
  4. {mdformat_mkdocs-5.2.0b1 → mdformat_mkdocs-5.2.0b2}/pyproject.toml +2 -2
  5. {mdformat_mkdocs-5.2.0b1 → mdformat_mkdocs-5.2.0b2}/LICENSE +0 -0
  6. {mdformat_mkdocs-5.2.0b1 → mdformat_mkdocs-5.2.0b2}/README.md +0 -0
  7. {mdformat_mkdocs-5.2.0b1 → mdformat_mkdocs-5.2.0b2}/mdformat_mkdocs/_helpers.py +0 -0
  8. {mdformat_mkdocs-5.2.0b1 → mdformat_mkdocs-5.2.0b2}/mdformat_mkdocs/_normalize_list.py +0 -0
  9. {mdformat_mkdocs-5.2.0b1 → mdformat_mkdocs-5.2.0b2}/mdformat_mkdocs/_postprocess_inline.py +0 -0
  10. {mdformat_mkdocs-5.2.0b1 → mdformat_mkdocs-5.2.0b2}/mdformat_mkdocs/_synced/__init__.py +0 -0
  11. {mdformat_mkdocs-5.2.0b1 → mdformat_mkdocs-5.2.0b2}/mdformat_mkdocs/_synced/admon_factories/README.md +0 -0
  12. {mdformat_mkdocs-5.2.0b1 → mdformat_mkdocs-5.2.0b2}/mdformat_mkdocs/_synced/admon_factories/__init__.py +0 -0
  13. {mdformat_mkdocs-5.2.0b1 → mdformat_mkdocs-5.2.0b2}/mdformat_mkdocs/_synced/admon_factories/_whitespace_admon_factories.py +0 -0
  14. {mdformat_mkdocs-5.2.0b1 → mdformat_mkdocs-5.2.0b2}/mdformat_mkdocs/mdit_plugins/__init__.py +0 -0
  15. {mdformat_mkdocs-5.2.0b1 → mdformat_mkdocs-5.2.0b2}/mdformat_mkdocs/mdit_plugins/_material_admon.py +0 -0
  16. {mdformat_mkdocs-5.2.0b1 → mdformat_mkdocs-5.2.0b2}/mdformat_mkdocs/mdit_plugins/_material_content_tabs.py +0 -0
  17. {mdformat_mkdocs-5.2.0b1 → mdformat_mkdocs-5.2.0b2}/mdformat_mkdocs/mdit_plugins/_material_deflist.py +0 -0
  18. {mdformat_mkdocs-5.2.0b1 → mdformat_mkdocs-5.2.0b2}/mdformat_mkdocs/mdit_plugins/_mkdocstrings_autorefs.py +0 -0
  19. {mdformat_mkdocs-5.2.0b1 → mdformat_mkdocs-5.2.0b2}/mdformat_mkdocs/mdit_plugins/_mkdocstrings_crossreference.py +0 -0
  20. {mdformat_mkdocs-5.2.0b1 → mdformat_mkdocs-5.2.0b2}/mdformat_mkdocs/mdit_plugins/_mkdocstrings_injection.py +0 -0
  21. {mdformat_mkdocs-5.2.0b1 → mdformat_mkdocs-5.2.0b2}/mdformat_mkdocs/mdit_plugins/_pymd_abbreviations.py +0 -0
  22. {mdformat_mkdocs-5.2.0b1 → mdformat_mkdocs-5.2.0b2}/mdformat_mkdocs/mdit_plugins/_pymd_admon.py +0 -0
  23. {mdformat_mkdocs-5.2.0b1 → mdformat_mkdocs-5.2.0b2}/mdformat_mkdocs/mdit_plugins/_pymd_arithmatex.py +0 -0
  24. {mdformat_mkdocs-5.2.0b1 → mdformat_mkdocs-5.2.0b2}/mdformat_mkdocs/mdit_plugins/_pymd_captions.py +0 -0
  25. {mdformat_mkdocs-5.2.0b1 → mdformat_mkdocs-5.2.0b2}/mdformat_mkdocs/mdit_plugins/_pymd_snippet.py +0 -0
  26. {mdformat_mkdocs-5.2.0b1 → mdformat_mkdocs-5.2.0b2}/mdformat_mkdocs/mdit_plugins/_python_markdown_attr_list.py +0 -0
  27. {mdformat_mkdocs-5.2.0b1 → mdformat_mkdocs-5.2.0b2}/mdformat_mkdocs/py.typed +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: mdformat_mkdocs
3
- Version: 5.2.0b1
3
+ Version: 5.2.0b2
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
@@ -1,7 +1,7 @@
1
1
  # ruff: noqa: RUF067
2
2
  """An mdformat plugin for `mkdocs`."""
3
3
 
4
- __version__ = "5.2.0b1"
4
+ __version__ = "5.2.0b2"
5
5
 
6
6
  __plugin_name__ = "mkdocs"
7
7
 
@@ -194,27 +194,51 @@ def _render_inline_content(node: RenderTreeNode, context: RenderContext) -> str:
194
194
 
195
195
 
196
196
  _ESCAPED_LINK_SPACED_URL = re.compile(r"\\\[([^\]]*)\\\]\(([^)]*[ ][^)]*)\)")
197
+ _PERCENT_ENCODED_URL_LINK = re.compile(r"\[([^\]]*)\]\(([^)]*%20[^)]*)\)")
198
+ _ANGLE_BRACKET_SPACED_URL_SOURCE = re.compile(r"\]\(<([^>]* [^>]*)>\)")
197
199
 
198
200
 
199
201
  def _fix_links_with_spaced_urls(
200
202
  text: str,
201
- node: RenderTreeNode, # noqa: ARG001
203
+ node: RenderTreeNode,
202
204
  context: RenderContext, # noqa: ARG001
203
205
  ) -> str:
204
- """Rewrite escaped links with space-containing URLs to angle-bracket syntax.
206
+ r"""Rewrite links with space-containing URLs to angle-bracket syntax.
205
207
 
206
208
  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
+ Handles two cases:
210
+
211
+ 1. markdown-it fails to parse [text](url space) as a link and mdformat
212
+ escapes the brackets — detects ``\\[text\\](url space)`` and rewrites to
213
+ ``[text](<url space>)``.
214
+ 2. markdown-it parses [text](<url space>) correctly but percent-encodes
215
+ the space in the href — detects [text](url%20space) and restores to
216
+ [text](<url space>) using the original source in node.content.
209
217
 
210
218
  Addresses: https://github.com/KyleKing/mdformat-mkdocs/issues/80
211
219
 
212
220
  """
213
- return _ESCAPED_LINK_SPACED_URL.sub(
221
+ text = _ESCAPED_LINK_SPACED_URL.sub(
214
222
  lambda m: f"[{m.group(1)}](<{m.group(2)}>)",
215
223
  text,
216
224
  )
217
225
 
226
+ spaced_urls_from_source = {
227
+ m.group(1) for m in _ANGLE_BRACKET_SPACED_URL_SOURCE.finditer(node.content)
228
+ }
229
+ if spaced_urls_from_source:
230
+
231
+ def _restore_spaced_url(m: re.Match[str]) -> str:
232
+ link_text, encoded_url = m.group(1), m.group(2)
233
+ decoded_url = encoded_url.replace("%20", " ")
234
+ if decoded_url in spaced_urls_from_source:
235
+ return f"[{link_text}](<{decoded_url}>)"
236
+ return m.group(0)
237
+
238
+ text = _PERCENT_ENCODED_URL_LINK.sub(_restore_spaced_url, text)
239
+
240
+ return text
241
+
218
242
 
219
243
  def _render_text(node: RenderTreeNode, context: RenderContext) -> str:
220
244
  r"""Re-escape dollar signs that mdformat core stripped.
@@ -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.2.0b1"
28
+ version = "5.2.0b2"
29
29
 
30
30
  [project.entry-points."mdformat.parser_extension"]
31
31
  mkdocs = "mdformat_mkdocs"
@@ -70,7 +70,7 @@ homepage = "https://github.com/kyleking/mdformat-mkdocs"
70
70
 
71
71
  [tool.commitizen]
72
72
  tag_format = "v${version}"
73
- version = "5.2.0b1"
73
+ version = "5.2.0b2"
74
74
  version_files = ["mdformat_mkdocs/__init__.py", "pyproject.toml:^version"]
75
75
 
76
76
  [tool.mypy]