mdformat-mkdocs 4.5.1__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 (25) hide show
  1. mdformat_mkdocs-4.5.1/LICENSE +21 -0
  2. mdformat_mkdocs-4.5.1/PKG-INFO +183 -0
  3. mdformat_mkdocs-4.5.1/README.md +143 -0
  4. mdformat_mkdocs-4.5.1/mdformat_mkdocs/__init__.py +11 -0
  5. mdformat_mkdocs-4.5.1/mdformat_mkdocs/_helpers.py +59 -0
  6. mdformat_mkdocs-4.5.1/mdformat_mkdocs/_normalize_list.py +507 -0
  7. mdformat_mkdocs-4.5.1/mdformat_mkdocs/_postprocess_inline.py +80 -0
  8. mdformat_mkdocs-4.5.1/mdformat_mkdocs/_synced/__init__.py +0 -0
  9. mdformat_mkdocs-4.5.1/mdformat_mkdocs/_synced/admon_factories/README.md +25 -0
  10. mdformat_mkdocs-4.5.1/mdformat_mkdocs/_synced/admon_factories/__init__.py +15 -0
  11. mdformat_mkdocs-4.5.1/mdformat_mkdocs/_synced/admon_factories/_whitespace_admon_factories.py +227 -0
  12. mdformat_mkdocs-4.5.1/mdformat_mkdocs/mdit_plugins/__init__.py +57 -0
  13. mdformat_mkdocs-4.5.1/mdformat_mkdocs/mdit_plugins/_material_admon.py +115 -0
  14. mdformat_mkdocs-4.5.1/mdformat_mkdocs/mdit_plugins/_material_content_tabs.py +108 -0
  15. mdformat_mkdocs-4.5.1/mdformat_mkdocs/mdit_plugins/_material_deflist.py +113 -0
  16. mdformat_mkdocs-4.5.1/mdformat_mkdocs/mdit_plugins/_mkdocstrings_autorefs.py +128 -0
  17. mdformat_mkdocs-4.5.1/mdformat_mkdocs/mdit_plugins/_mkdocstrings_crossreference.py +56 -0
  18. mdformat_mkdocs-4.5.1/mdformat_mkdocs/mdit_plugins/_pymd_abbreviations.py +102 -0
  19. mdformat_mkdocs-4.5.1/mdformat_mkdocs/mdit_plugins/_pymd_admon.py +85 -0
  20. mdformat_mkdocs-4.5.1/mdformat_mkdocs/mdit_plugins/_pymd_captions.py +122 -0
  21. mdformat_mkdocs-4.5.1/mdformat_mkdocs/mdit_plugins/_pymd_snippet.py +103 -0
  22. mdformat_mkdocs-4.5.1/mdformat_mkdocs/mdit_plugins/_python_markdown_attr_list.py +60 -0
  23. mdformat_mkdocs-4.5.1/mdformat_mkdocs/plugin.py +242 -0
  24. mdformat_mkdocs-4.5.1/mdformat_mkdocs/py.typed +0 -0
  25. mdformat_mkdocs-4.5.1/pyproject.toml +221 -0
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 Kyle King
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,183 @@
1
+ Metadata-Version: 2.4
2
+ Name: mdformat_mkdocs
3
+ Version: 4.5.1
4
+ Keywords: markdown,markdown-it,mdformat,mdformat_plugin_template
5
+ Author: kyleking
6
+ Author-email: kyleking <dev.act.kyle@gmail.com>
7
+ License-Expression: MIT
8
+ License-File: LICENSE
9
+ Classifier: Intended Audience :: Developers
10
+ Classifier: License :: OSI Approved :: MIT License
11
+ Classifier: Programming Language :: Python :: 3
12
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
13
+ Requires-Dist: mdformat>=0.7.19
14
+ Requires-Dist: mdformat-gfm>=0.3.6
15
+ Requires-Dist: mdit-py-plugins>=0.4.1
16
+ Requires-Dist: more-itertools>=10.5.0
17
+ Requires-Dist: mdformat-beautysh>=0.1.1 ; extra == 'recommended'
18
+ Requires-Dist: mdformat-config>=0.2.1 ; extra == 'recommended'
19
+ Requires-Dist: mdformat-footnote>=0.1.1 ; extra == 'recommended'
20
+ Requires-Dist: mdformat-frontmatter>=2.0.8 ; extra == 'recommended'
21
+ Requires-Dist: mdformat-gfm>=1.0.0 ; python_full_version >= '3.10' and extra == 'recommended'
22
+ Requires-Dist: mdformat-ruff>=0.1.3 ; extra == 'recommended'
23
+ Requires-Dist: mdformat-simple-breaks>=0.0.1 ; extra == 'recommended'
24
+ Requires-Dist: mdformat-tables>=0.4.0 ; python_full_version < '3.10' and extra == 'recommended'
25
+ Requires-Dist: mdformat-web>=0.2.0 ; extra == 'recommended'
26
+ Requires-Dist: mdformat-wikilink>=0.2.0 ; extra == 'recommended'
27
+ Requires-Dist: setuptools ; extra == 'recommended'
28
+ Requires-Dist: beartype>=0.21.0 ; extra == 'test'
29
+ Requires-Dist: pytest>=9.0.1 ; extra == 'test'
30
+ Requires-Dist: pytest-beartype>=0.2.0 ; extra == 'test'
31
+ Requires-Dist: pytest-cov>=7.0.0 ; extra == 'test'
32
+ Requires-Dist: syrupy>=4.9.1 ; extra == 'test'
33
+ Requires-Python: >=3.10.0
34
+ Project-URL: Bug Tracker, https://github.com/kyleking/mdformat-mkdocs/issues
35
+ Project-URL: Changelog, https://github.com/kyleking/mdformat-mkdocs/releases
36
+ Project-URL: homepage, https://github.com/kyleking/mdformat-mkdocs
37
+ Provides-Extra: recommended
38
+ Provides-Extra: test
39
+ Description-Content-Type: text/markdown
40
+
41
+ # mdformat-mkdocs
42
+
43
+ [![Build Status][ci-badge]][ci-link] [![PyPI version][pypi-badge]][pypi-link]
44
+
45
+ <!-- [![codecov.io][cov-badge]][cov-link]
46
+ [cov-badge]: https://codecov.io/gh/executablebooks/mdformat-mkdocs/branch/main/graph/badge.svg
47
+ [cov-link]: https://codecov.io/gh/executablebooks/mdformat-mkdocs
48
+ -->
49
+
50
+ An [mdformat](https://github.com/executablebooks/mdformat) plugin for [mkdocs](https://github.com/mkdocs/mkdocs) and packages commonly used with MkDocs ([mkdocs-material](https://squidfunk.github.io/mkdocs-material), [mkdocstrings](https://mkdocstrings.github.io), and [python-markdown](https://python-markdown.github.io))
51
+
52
+ Supports:
53
+
54
+ - Indents are converted to four-spaces instead of two
55
+ - *Note*: when specifying `--align-semantic-breaks-in-lists`, the nested indent for ordered lists is three, but is otherwise a multiple of four
56
+ - Unordered list bullets are converted to dashes (`-`) instead of `*`
57
+ - By default, ordered lists are standardized on a single digit (`1.` or `0.`) unless `--number` is specified, then `mdformat-mkdocs` will apply consecutive numbering to ordered lists [for consistency with `mdformat`](https://github.com/executablebooks/mdformat?tab=readme-ov-file#options)
58
+ - [MkDocs-Material Admonitions\*](https://squidfunk.github.io/mkdocs-material/reference/admonitions)
59
+ - \*Note: `mdformat-admon` will format the same admonitions, but for consistency with the mkdocs styleguide, an extra space will be added by this package ([#22](https://github.com/KyleKing/mdformat-admon/pull/22))
60
+ - [MkDocs-Material Content Tabs\*](https://squidfunk.github.io/mkdocs-material/reference/content-tabs)
61
+ - \*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.
62
+ - [MkDocs-Material Definition Lists](https://squidfunk.github.io/mkdocs-material/reference/lists/#using-definition-lists)
63
+ - [mkdocstrings Anchors (autorefs)](https://mkdocstrings.github.io/autorefs/#markdown-anchors)
64
+ - [mkdocstrings Cross-References](https://mkdocstrings.github.io/usage/#cross-references)
65
+ - [Python Markdown "Abbreviations"\*](https://squidfunk.github.io/mkdocs-material/reference/tooltips/#adding-abbreviations)
66
+ - \*Note: the markup (HTML) rendered for abbreviations is not useful for rendering. If important, I'm open to contributions because the implementation could be challenging
67
+ - [Python Markdown "Snippets"\*](https://facelessuser.github.io/pymdown-extensions/extensions/snippets)
68
+ - \*Note: the markup (HTML) renders the plain text without implementing the snippet logic. I'm open to contributions if anyone needs full support for snippets
69
+
70
+ See the example test files, [./tests/pre-commit-test.md](https://raw.githubusercontent.com/KyleKing/mdformat-mkdocs/main/tests/pre-commit-test.md) and [./tests/format/fixtures.md](https://raw.githubusercontent.com/KyleKing/mdformat-mkdocs/main/tests/format/fixtures.md)
71
+
72
+ ## `mdformat` Usage
73
+
74
+ Add this package wherever you use `mdformat` and the plugin will be auto-recognized. No additional configuration necessary. For additional information on plugins, see [the official `mdformat` documentation here](https://mdformat.readthedocs.io/en/stable/users/plugins.html)
75
+
76
+ **Tip**: this package specifies an "extra" (`'recommended'`) for plugins that work well with typical documentation managed by `mkdocs`:
77
+
78
+ - [mdformat-beautysh](https://pypi.org/project/mdformat-beautysh)
79
+ - [mdformat-black](https://pypi.org/project/mdformat-black)
80
+ - [mdformat-config](https://pypi.org/project/mdformat-config)
81
+ - [mdformat-footnote](https://pypi.org/project/mdformat-footnote)
82
+ - [mdformat-frontmatter](https://pypi.org/project/mdformat-frontmatter)
83
+ - [mdformat-simple-breaks](https://pypi.org/project/mdformat-simple-breaks)
84
+ - [mdformat-web](https://pypi.org/project/mdformat-web)
85
+ - [mdformat-wikilink](https://github.com/tmr232/mdformat-wikilink)
86
+
87
+ ### pre-commit/prek
88
+
89
+ ```yaml
90
+ repos:
91
+ - repo: https://github.com/executablebooks/mdformat
92
+ rev: 0.7.19
93
+ hooks:
94
+ - id: mdformat
95
+ additional_dependencies:
96
+ - mdformat-mkdocs
97
+ # Or
98
+ # - "mdformat-mkdocs[recommended]"
99
+ ```
100
+
101
+ ### pipx/uv
102
+
103
+ ```sh
104
+ pipx install mdformat
105
+ pipx inject mdformat mdformat-mkdocs
106
+ ```
107
+
108
+ Or with uv:
109
+
110
+ ```sh
111
+ uv tool run --from mdformat-mkdocs mdformat
112
+ ```
113
+
114
+ ## HTML Rendering
115
+
116
+ To generate HTML output, any of the plugins can be imported from `mdit_plugins`. For more guidance on `MarkdownIt`, see the docs: <https://markdown-it-py.readthedocs.io/en/latest/using.html#the-parser>
117
+
118
+ ```py
119
+ from markdown_it import MarkdownIt
120
+
121
+ from mdformat_mkdocs.mdit_plugins import (
122
+ material_admon_plugin,
123
+ material_content_tabs_plugin,
124
+ mkdocstrings_autorefs_plugin,
125
+ mkdocstrings_crossreference_plugin,
126
+ pymd_abbreviations_plugin,
127
+ )
128
+
129
+ md = MarkdownIt()
130
+ md.use(material_admon_plugin)
131
+ md.use(material_content_tabs_plugin)
132
+ md.use(mkdocstrings_autorefs_plugin)
133
+ md.use(mkdocstrings_crossreference_plugin)
134
+ md.use(pymd_abbreviations_plugin)
135
+
136
+ text = "- Line 1\n - `bash command`\n - Line 3"
137
+ md.render(text)
138
+ # <ul>
139
+ # <li>Line 1
140
+ # <ul>
141
+ # <li><code>bash command</code></li>
142
+ # <li>Line 3</li>
143
+ # </ul>
144
+ # </li>
145
+ # </ul>
146
+ ```
147
+
148
+ ## Configuration
149
+
150
+ `mdformat-mkdocs` adds the CLI arguments:
151
+
152
+ - `--align-semantic-breaks-in-lists` to optionally align line breaks in numbered lists to 3-spaces. If not specified, the default of 4-indents is followed universally.
153
+
154
+ ```txt
155
+ # with: mdformat
156
+ 1. Semantic line feed where the following line is
157
+ three spaces deep
158
+
159
+ # vs. "mdformat --align-semantic-breaks-in-lists"
160
+ 1. Semantic line feed where the following line is
161
+ three spaces deep
162
+ ```
163
+
164
+ - `--ignore-missing-references` if set, do not escape link references when no definition is found. This is required when references are dynamic, such as with python mkdocstrings
165
+
166
+ You can also use the toml configuration (https://mdformat.readthedocs.io/en/stable/users/configuration_file.html):
167
+
168
+ ```toml
169
+ # .mdformat.toml
170
+
171
+ [plugin.mkdocs]
172
+ align_semantic_breaks_in_lists = true
173
+ ignore_missing_references = true
174
+ ```
175
+
176
+ ## Contributing
177
+
178
+ See [CONTRIBUTING.md](https://github.com/kyleking/mdformat-mkdocs/blob/main/CONTRIBUTING.md)
179
+
180
+ [ci-badge]: https://github.com/kyleking/mdformat-mkdocs/workflows/CI/badge.svg?branch=main
181
+ [ci-link]: https://github.com/kyleking/mdformat-mkdocs/actions?query=workflow%3ACI+branch%3Amain+event%3Apush
182
+ [pypi-badge]: https://img.shields.io/pypi/v/mdformat-mkdocs.svg
183
+ [pypi-link]: https://pypi.org/project/mdformat-mkdocs
@@ -0,0 +1,143 @@
1
+ # mdformat-mkdocs
2
+
3
+ [![Build Status][ci-badge]][ci-link] [![PyPI version][pypi-badge]][pypi-link]
4
+
5
+ <!-- [![codecov.io][cov-badge]][cov-link]
6
+ [cov-badge]: https://codecov.io/gh/executablebooks/mdformat-mkdocs/branch/main/graph/badge.svg
7
+ [cov-link]: https://codecov.io/gh/executablebooks/mdformat-mkdocs
8
+ -->
9
+
10
+ An [mdformat](https://github.com/executablebooks/mdformat) plugin for [mkdocs](https://github.com/mkdocs/mkdocs) and packages commonly used with MkDocs ([mkdocs-material](https://squidfunk.github.io/mkdocs-material), [mkdocstrings](https://mkdocstrings.github.io), and [python-markdown](https://python-markdown.github.io))
11
+
12
+ Supports:
13
+
14
+ - Indents are converted to four-spaces instead of two
15
+ - *Note*: when specifying `--align-semantic-breaks-in-lists`, the nested indent for ordered lists is three, but is otherwise a multiple of four
16
+ - Unordered list bullets are converted to dashes (`-`) instead of `*`
17
+ - By default, ordered lists are standardized on a single digit (`1.` or `0.`) unless `--number` is specified, then `mdformat-mkdocs` will apply consecutive numbering to ordered lists [for consistency with `mdformat`](https://github.com/executablebooks/mdformat?tab=readme-ov-file#options)
18
+ - [MkDocs-Material Admonitions\*](https://squidfunk.github.io/mkdocs-material/reference/admonitions)
19
+ - \*Note: `mdformat-admon` will format the same admonitions, but for consistency with the mkdocs styleguide, an extra space will be added by this package ([#22](https://github.com/KyleKing/mdformat-admon/pull/22))
20
+ - [MkDocs-Material Content Tabs\*](https://squidfunk.github.io/mkdocs-material/reference/content-tabs)
21
+ - \*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.
22
+ - [MkDocs-Material Definition Lists](https://squidfunk.github.io/mkdocs-material/reference/lists/#using-definition-lists)
23
+ - [mkdocstrings Anchors (autorefs)](https://mkdocstrings.github.io/autorefs/#markdown-anchors)
24
+ - [mkdocstrings Cross-References](https://mkdocstrings.github.io/usage/#cross-references)
25
+ - [Python Markdown "Abbreviations"\*](https://squidfunk.github.io/mkdocs-material/reference/tooltips/#adding-abbreviations)
26
+ - \*Note: the markup (HTML) rendered for abbreviations is not useful for rendering. If important, I'm open to contributions because the implementation could be challenging
27
+ - [Python Markdown "Snippets"\*](https://facelessuser.github.io/pymdown-extensions/extensions/snippets)
28
+ - \*Note: the markup (HTML) renders the plain text without implementing the snippet logic. I'm open to contributions if anyone needs full support for snippets
29
+
30
+ See the example test files, [./tests/pre-commit-test.md](https://raw.githubusercontent.com/KyleKing/mdformat-mkdocs/main/tests/pre-commit-test.md) and [./tests/format/fixtures.md](https://raw.githubusercontent.com/KyleKing/mdformat-mkdocs/main/tests/format/fixtures.md)
31
+
32
+ ## `mdformat` Usage
33
+
34
+ Add this package wherever you use `mdformat` and the plugin will be auto-recognized. No additional configuration necessary. For additional information on plugins, see [the official `mdformat` documentation here](https://mdformat.readthedocs.io/en/stable/users/plugins.html)
35
+
36
+ **Tip**: this package specifies an "extra" (`'recommended'`) for plugins that work well with typical documentation managed by `mkdocs`:
37
+
38
+ - [mdformat-beautysh](https://pypi.org/project/mdformat-beautysh)
39
+ - [mdformat-black](https://pypi.org/project/mdformat-black)
40
+ - [mdformat-config](https://pypi.org/project/mdformat-config)
41
+ - [mdformat-footnote](https://pypi.org/project/mdformat-footnote)
42
+ - [mdformat-frontmatter](https://pypi.org/project/mdformat-frontmatter)
43
+ - [mdformat-simple-breaks](https://pypi.org/project/mdformat-simple-breaks)
44
+ - [mdformat-web](https://pypi.org/project/mdformat-web)
45
+ - [mdformat-wikilink](https://github.com/tmr232/mdformat-wikilink)
46
+
47
+ ### pre-commit/prek
48
+
49
+ ```yaml
50
+ repos:
51
+ - repo: https://github.com/executablebooks/mdformat
52
+ rev: 0.7.19
53
+ hooks:
54
+ - id: mdformat
55
+ additional_dependencies:
56
+ - mdformat-mkdocs
57
+ # Or
58
+ # - "mdformat-mkdocs[recommended]"
59
+ ```
60
+
61
+ ### pipx/uv
62
+
63
+ ```sh
64
+ pipx install mdformat
65
+ pipx inject mdformat mdformat-mkdocs
66
+ ```
67
+
68
+ Or with uv:
69
+
70
+ ```sh
71
+ uv tool run --from mdformat-mkdocs mdformat
72
+ ```
73
+
74
+ ## HTML Rendering
75
+
76
+ To generate HTML output, any of the plugins can be imported from `mdit_plugins`. For more guidance on `MarkdownIt`, see the docs: <https://markdown-it-py.readthedocs.io/en/latest/using.html#the-parser>
77
+
78
+ ```py
79
+ from markdown_it import MarkdownIt
80
+
81
+ from mdformat_mkdocs.mdit_plugins import (
82
+ material_admon_plugin,
83
+ material_content_tabs_plugin,
84
+ mkdocstrings_autorefs_plugin,
85
+ mkdocstrings_crossreference_plugin,
86
+ pymd_abbreviations_plugin,
87
+ )
88
+
89
+ md = MarkdownIt()
90
+ md.use(material_admon_plugin)
91
+ md.use(material_content_tabs_plugin)
92
+ md.use(mkdocstrings_autorefs_plugin)
93
+ md.use(mkdocstrings_crossreference_plugin)
94
+ md.use(pymd_abbreviations_plugin)
95
+
96
+ text = "- Line 1\n - `bash command`\n - Line 3"
97
+ md.render(text)
98
+ # <ul>
99
+ # <li>Line 1
100
+ # <ul>
101
+ # <li><code>bash command</code></li>
102
+ # <li>Line 3</li>
103
+ # </ul>
104
+ # </li>
105
+ # </ul>
106
+ ```
107
+
108
+ ## Configuration
109
+
110
+ `mdformat-mkdocs` adds the CLI arguments:
111
+
112
+ - `--align-semantic-breaks-in-lists` to optionally align line breaks in numbered lists to 3-spaces. If not specified, the default of 4-indents is followed universally.
113
+
114
+ ```txt
115
+ # with: mdformat
116
+ 1. Semantic line feed where the following line is
117
+ three spaces deep
118
+
119
+ # vs. "mdformat --align-semantic-breaks-in-lists"
120
+ 1. Semantic line feed where the following line is
121
+ three spaces deep
122
+ ```
123
+
124
+ - `--ignore-missing-references` if set, do not escape link references when no definition is found. This is required when references are dynamic, such as with python mkdocstrings
125
+
126
+ You can also use the toml configuration (https://mdformat.readthedocs.io/en/stable/users/configuration_file.html):
127
+
128
+ ```toml
129
+ # .mdformat.toml
130
+
131
+ [plugin.mkdocs]
132
+ align_semantic_breaks_in_lists = true
133
+ ignore_missing_references = true
134
+ ```
135
+
136
+ ## Contributing
137
+
138
+ See [CONTRIBUTING.md](https://github.com/kyleking/mdformat-mkdocs/blob/main/CONTRIBUTING.md)
139
+
140
+ [ci-badge]: https://github.com/kyleking/mdformat-mkdocs/workflows/CI/badge.svg?branch=main
141
+ [ci-link]: https://github.com/kyleking/mdformat-mkdocs/actions?query=workflow%3ACI+branch%3Amain+event%3Apush
142
+ [pypi-badge]: https://img.shields.io/pypi/v/mdformat-mkdocs.svg
143
+ [pypi-link]: https://pypi.org/project/mdformat-mkdocs
@@ -0,0 +1,11 @@
1
+ """An mdformat plugin for `mkdocs`."""
2
+
3
+ __version__ = "4.5.1"
4
+
5
+ __plugin_name__ = "mkdocs"
6
+
7
+ # FYI see source code for available interfaces:
8
+ # https://github.com/executablebooks/mdformat/blob/5d9b573ce33bae219087984dd148894c774f41d4/src/mdformat/plugins.py
9
+ from .plugin import POSTPROCESSORS, RENDERERS, add_cli_argument_group, update_mdit
10
+
11
+ __all__ = ("POSTPROCESSORS", "RENDERERS", "add_cli_argument_group", "update_mdit")
@@ -0,0 +1,59 @@
1
+ """General Helpers."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import re
6
+ from collections.abc import Callable, Mapping
7
+ from functools import wraps
8
+ from typing import Any
9
+
10
+ from . import __plugin_name__
11
+
12
+ EOL = "\n"
13
+ """Line delimiter."""
14
+
15
+ MKDOCS_INDENT_COUNT = 4
16
+ """Use 4-spaces for mkdocs."""
17
+
18
+ FILLER_CHAR = "𝕏" # noqa: RUF001
19
+ """A spacer that is inserted and then removed to ensure proper word wrap."""
20
+
21
+
22
+ def rstrip_result(func: Callable[..., str]) -> Callable[..., str]:
23
+ """Right-strip the decorated function's result.
24
+
25
+ Returns:
26
+ Callable[..., str]: decorator
27
+
28
+ """
29
+
30
+ @wraps(func)
31
+ def _wrapper(*args, **kwargs) -> str:
32
+ return func(*args, **kwargs).rstrip()
33
+
34
+ return _wrapper
35
+
36
+
37
+ def separate_indent(line: str) -> tuple[str, str]:
38
+ """Separate leading indent from content. Also used by the test suite.
39
+
40
+ Returns:
41
+ tuple[str, str]: separate indent and content
42
+
43
+ """
44
+ re_indent = re.compile(r"(?P<indent>\s*)(?P<content>[^\s]?.*)")
45
+ match = re_indent.match(line)
46
+ assert match # for pyright
47
+ return (match["indent"], match["content"])
48
+
49
+
50
+ ContextOptions = Mapping[str, Any]
51
+
52
+
53
+ def get_conf(options: ContextOptions, key: str) -> bool | str | int | None:
54
+ """Read setting from mdformat configuration Context."""
55
+ if (api := options["mdformat"].get(key)) is not None:
56
+ return api # From API
57
+ return (
58
+ options["mdformat"].get("plugin", {}).get(__plugin_name__, {}).get(key)
59
+ ) # from cli_or_toml