mkdocs-include-markdown-plugin 7.1.6__tar.gz → 7.1.8__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.
- {mkdocs_include_markdown_plugin-7.1.6 → mkdocs_include_markdown_plugin-7.1.8}/PKG-INFO +1 -1
- {mkdocs_include_markdown_plugin-7.1.6 → mkdocs_include_markdown_plugin-7.1.8}/pyproject.toml +1 -1
- {mkdocs_include_markdown_plugin-7.1.6 → mkdocs_include_markdown_plugin-7.1.8}/src/mkdocs_include_markdown_plugin/cache.py +1 -1
- {mkdocs_include_markdown_plugin-7.1.6 → mkdocs_include_markdown_plugin-7.1.8}/src/mkdocs_include_markdown_plugin/directive.py +1 -1
- {mkdocs_include_markdown_plugin-7.1.6 → mkdocs_include_markdown_plugin-7.1.8}/src/mkdocs_include_markdown_plugin/event.py +36 -59
- mkdocs_include_markdown_plugin-7.1.8/src/mkdocs_include_markdown_plugin/placeholders.py +37 -0
- {mkdocs_include_markdown_plugin-7.1.6 → mkdocs_include_markdown_plugin-7.1.8}/src/mkdocs_include_markdown_plugin/process.py +11 -9
- {mkdocs_include_markdown_plugin-7.1.6 → mkdocs_include_markdown_plugin-7.1.8}/.gitignore +0 -0
- {mkdocs_include_markdown_plugin-7.1.6 → mkdocs_include_markdown_plugin-7.1.8}/LICENSE +0 -0
- {mkdocs_include_markdown_plugin-7.1.6 → mkdocs_include_markdown_plugin-7.1.8}/README.md +0 -0
- {mkdocs_include_markdown_plugin-7.1.6 → mkdocs_include_markdown_plugin-7.1.8}/src/mkdocs_include_markdown_plugin/__init__.py +0 -0
- {mkdocs_include_markdown_plugin-7.1.6 → mkdocs_include_markdown_plugin-7.1.8}/src/mkdocs_include_markdown_plugin/config.py +0 -0
- {mkdocs_include_markdown_plugin-7.1.6 → mkdocs_include_markdown_plugin-7.1.8}/src/mkdocs_include_markdown_plugin/files_watcher.py +0 -0
- {mkdocs_include_markdown_plugin-7.1.6 → mkdocs_include_markdown_plugin-7.1.8}/src/mkdocs_include_markdown_plugin/logger.py +0 -0
- {mkdocs_include_markdown_plugin-7.1.6 → mkdocs_include_markdown_plugin-7.1.8}/src/mkdocs_include_markdown_plugin/plugin.py +0 -0
- {mkdocs_include_markdown_plugin-7.1.6 → mkdocs_include_markdown_plugin-7.1.8}/src/mkdocs_include_markdown_plugin/py.typed +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: mkdocs-include-markdown-plugin
|
|
3
|
-
Version: 7.1.
|
|
3
|
+
Version: 7.1.8
|
|
4
4
|
Summary: Mkdocs Markdown includer plugin.
|
|
5
5
|
Project-URL: Source, https://github.com/mondeja/mkdocs-include-markdown-plugin
|
|
6
6
|
Project-URL: Documentation, https://github.com/mondeja/mkdocs-include-markdown-plugin#documentation
|
|
@@ -208,7 +208,7 @@ def parse_filename_argument(
|
|
|
208
208
|
|
|
209
209
|
def parse_string_argument(match: re.Match[str] | None) -> str | None:
|
|
210
210
|
"""Return the string argument matched by ``match``."""
|
|
211
|
-
if match is None:
|
|
211
|
+
if match is None: # pragma: no cover
|
|
212
212
|
return None
|
|
213
213
|
value = match[1]
|
|
214
214
|
if value is None:
|
|
@@ -28,10 +28,15 @@ from mkdocs_include_markdown_plugin.directive import (
|
|
|
28
28
|
)
|
|
29
29
|
from mkdocs_include_markdown_plugin.files_watcher import FilesWatcher
|
|
30
30
|
from mkdocs_include_markdown_plugin.logger import logger
|
|
31
|
+
from mkdocs_include_markdown_plugin.placeholders import (
|
|
32
|
+
escape_placeholders,
|
|
33
|
+
save_placeholder,
|
|
34
|
+
unescape_placeholders,
|
|
35
|
+
)
|
|
31
36
|
|
|
32
37
|
|
|
33
38
|
if TYPE_CHECKING: # pragma: no cover
|
|
34
|
-
from typing import
|
|
39
|
+
from typing import TypedDict
|
|
35
40
|
|
|
36
41
|
from mkdocs.structure.pages import Page
|
|
37
42
|
|
|
@@ -46,23 +51,6 @@ if TYPE_CHECKING: # pragma: no cover
|
|
|
46
51
|
)
|
|
47
52
|
|
|
48
53
|
|
|
49
|
-
# Placeholders (taken from Python-Markdown)
|
|
50
|
-
STX = '\u0002'
|
|
51
|
-
''' "Start of Text" marker for placeholder templates. '''
|
|
52
|
-
ETX = '\u0003'
|
|
53
|
-
''' "End of Text" marker for placeholder templates. '''
|
|
54
|
-
INLINE_PLACEHOLDER_PREFIX = f'{STX}klzzwxh:'
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
def build_placeholder(
|
|
58
|
-
num: int,
|
|
59
|
-
directive: Literal['include', 'include-markdown'],
|
|
60
|
-
) -> str:
|
|
61
|
-
"""Return a placeholder."""
|
|
62
|
-
directive_prefix = 'im' if directive == 'include-markdown' else 'i'
|
|
63
|
-
return f'{INLINE_PLACEHOLDER_PREFIX}{directive_prefix}{num}{ETX}'
|
|
64
|
-
|
|
65
|
-
|
|
66
54
|
@dataclass
|
|
67
55
|
class Settings: # noqa: D101
|
|
68
56
|
exclude: list[str] | None
|
|
@@ -98,8 +86,8 @@ def get_file_content( # noqa: PLR0913, PLR0915
|
|
|
98
86
|
else:
|
|
99
87
|
settings_ignore_paths = []
|
|
100
88
|
|
|
101
|
-
|
|
102
|
-
|
|
89
|
+
markdown = escape_placeholders(markdown)
|
|
90
|
+
placeholders_contents: list[tuple[str, str]] = []
|
|
103
91
|
|
|
104
92
|
def found_include_tag( # noqa: PLR0912, PLR0915
|
|
105
93
|
match: re.Match[str],
|
|
@@ -311,11 +299,7 @@ def get_file_content( # noqa: PLR0913, PLR0915
|
|
|
311
299
|
f' {readable_files_to_include}',
|
|
312
300
|
)
|
|
313
301
|
|
|
314
|
-
|
|
315
|
-
include_index = len(new_found_include_contents)
|
|
316
|
-
placeholder = build_placeholder(include_index, 'include')
|
|
317
|
-
new_found_include_contents.append((placeholder, text_to_include))
|
|
318
|
-
return placeholder
|
|
302
|
+
return save_placeholder(placeholders_contents, text_to_include)
|
|
319
303
|
|
|
320
304
|
def found_include_markdown_tag( # noqa: PLR0912, PLR0915
|
|
321
305
|
match: re.Match[str],
|
|
@@ -436,27 +420,30 @@ def get_file_content( # noqa: PLR0913, PLR0915
|
|
|
436
420
|
offset_match = ARGUMENT_REGEXES['heading-offset']().search(
|
|
437
421
|
arguments_string,
|
|
438
422
|
)
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
423
|
+
try:
|
|
424
|
+
# Here None[1] would raise a TypeError
|
|
425
|
+
offset_raw_value = offset_match[1] # type: ignore
|
|
426
|
+
except (IndexError, TypeError): # pragma: no cover
|
|
427
|
+
offset_raw_value = ''
|
|
428
|
+
if offset_raw_value == '':
|
|
429
|
+
location = process.file_lineno_message(
|
|
430
|
+
page_src_path, docs_dir, directive_lineno(),
|
|
431
|
+
)
|
|
432
|
+
raise PluginError(
|
|
433
|
+
"Invalid empty 'heading-offset' argument in"
|
|
434
|
+
f" 'include-markdown' directive at {location}",
|
|
435
|
+
)
|
|
436
|
+
try:
|
|
437
|
+
offset = int(offset_raw_value)
|
|
438
|
+
except ValueError:
|
|
439
|
+
location = process.file_lineno_message(
|
|
440
|
+
page_src_path, docs_dir, directive_lineno(),
|
|
441
|
+
)
|
|
442
|
+
raise PluginError(
|
|
443
|
+
f"Invalid 'heading-offset' argument"
|
|
444
|
+
f" '{offset_raw_value}' in 'include-markdown'"
|
|
445
|
+
f" directive at {location}",
|
|
446
|
+
) from None
|
|
460
447
|
|
|
461
448
|
bool_options, invalid_bool_args = parse_bool_options(
|
|
462
449
|
[
|
|
@@ -604,15 +591,7 @@ def get_file_content( # noqa: PLR0913, PLR0915
|
|
|
604
591
|
f' {readable_files_to_include}',
|
|
605
592
|
)
|
|
606
593
|
|
|
607
|
-
|
|
608
|
-
markdown_include_index = len(new_found_include_markdown_contents)
|
|
609
|
-
placeholder = build_placeholder(
|
|
610
|
-
markdown_include_index, 'include-markdown',
|
|
611
|
-
)
|
|
612
|
-
new_found_include_markdown_contents.append(
|
|
613
|
-
(placeholder, text_to_include),
|
|
614
|
-
)
|
|
615
|
-
return placeholder
|
|
594
|
+
return save_placeholder(placeholders_contents, text_to_include)
|
|
616
595
|
|
|
617
596
|
# Replace contents by placeholders
|
|
618
597
|
markdown = tags['include-markdown'].sub(
|
|
@@ -625,11 +604,9 @@ def get_file_content( # noqa: PLR0913, PLR0915
|
|
|
625
604
|
)
|
|
626
605
|
|
|
627
606
|
# Replace placeholders by contents
|
|
628
|
-
for placeholder, text in
|
|
629
|
-
markdown = markdown.replace(placeholder, text, 1)
|
|
630
|
-
for placeholder, text in new_found_include_markdown_contents:
|
|
607
|
+
for placeholder, text in placeholders_contents:
|
|
631
608
|
markdown = markdown.replace(placeholder, text, 1)
|
|
632
|
-
return markdown
|
|
609
|
+
return unescape_placeholders(markdown)
|
|
633
610
|
|
|
634
611
|
|
|
635
612
|
def on_page_markdown(
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"""Module for placeholders processing."""
|
|
2
|
+
|
|
3
|
+
# Placeholders (taken from Python-Markdown)
|
|
4
|
+
from __future__ import annotations
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
STX = '\u0002'
|
|
8
|
+
''' "Start of Text" marker for placeholder templates. '''
|
|
9
|
+
ETX = '\u0003'
|
|
10
|
+
''' "End of Text" marker for placeholder templates. '''
|
|
11
|
+
INLINE_PLACEHOLDER_PREFIX = f'{STX}klzzwxh:'
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
def build_placeholder(num: int) -> str:
|
|
15
|
+
"""Return a placeholder."""
|
|
16
|
+
return f'{INLINE_PLACEHOLDER_PREFIX}{num}{ETX}'
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
def escape_placeholders(text: str) -> str:
|
|
20
|
+
"""Escape placeholders in the given text."""
|
|
21
|
+
return text.replace(STX, f'\\{STX}').replace(ETX, f'\\{ETX}')
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
def unescape_placeholders(text: str) -> str:
|
|
25
|
+
"""Unescape placeholders in the given text."""
|
|
26
|
+
return text.replace(f'\\{STX}', STX).replace(f'\\{ETX}', ETX)
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
def save_placeholder(
|
|
30
|
+
placeholders_contents: list[tuple[str, str]],
|
|
31
|
+
text_to_include: str,
|
|
32
|
+
) -> str:
|
|
33
|
+
"""Save the included text and return the placeholder."""
|
|
34
|
+
inclusion_index = len(placeholders_contents)
|
|
35
|
+
placeholder = build_placeholder(inclusion_index)
|
|
36
|
+
placeholders_contents.append((placeholder, text_to_include))
|
|
37
|
+
return placeholder
|
|
@@ -33,7 +33,7 @@ if TYPE_CHECKING: # pragma: no cover
|
|
|
33
33
|
# previous to Python3.11. Also, these nested brackets can be recursive in the
|
|
34
34
|
# Perl implementation but this doesn't seem possible in Python, the current
|
|
35
35
|
# implementation only reaches two levels.
|
|
36
|
-
MARKDOWN_LINK_REGEX = re.compile(
|
|
36
|
+
MARKDOWN_LINK_REGEX = re.compile(
|
|
37
37
|
r'''
|
|
38
38
|
( # wrap whole match in $1
|
|
39
39
|
(?<!!) # don't match images - negative lookbehind
|
|
@@ -427,17 +427,19 @@ def filter_inclusions( # noqa: PLR0912
|
|
|
427
427
|
def _transform_negative_offset_func_factory(
|
|
428
428
|
offset: int,
|
|
429
429
|
) -> Callable[[str], str]:
|
|
430
|
-
|
|
430
|
+
abs_offset = abs(offset)
|
|
431
431
|
|
|
432
432
|
def transform(line: str) -> str:
|
|
433
433
|
try:
|
|
434
434
|
if line[0] != '#':
|
|
435
435
|
return line
|
|
436
436
|
except IndexError: # pragma: no cover
|
|
437
|
+
# Note for pragma: all lines include a newline
|
|
438
|
+
# so this exception is never raised in tests.
|
|
437
439
|
return line
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
return '#' +
|
|
440
|
+
stripped_line = line.lstrip('#')
|
|
441
|
+
new_n_headings = max(len(line) - len(stripped_line) - abs_offset, 1)
|
|
442
|
+
return '#' * new_n_headings + stripped_line
|
|
441
443
|
|
|
442
444
|
return transform
|
|
443
445
|
|
|
@@ -449,11 +451,11 @@ def _transform_positive_offset_func_factory(
|
|
|
449
451
|
|
|
450
452
|
def transform(line: str) -> str:
|
|
451
453
|
try:
|
|
452
|
-
|
|
454
|
+
if line[0] != '#':
|
|
455
|
+
return line
|
|
453
456
|
except IndexError: # pragma: no cover
|
|
454
457
|
return line
|
|
455
|
-
|
|
456
|
-
return heading_prefix + line if prefix == '#' else line
|
|
458
|
+
return heading_prefix + line
|
|
457
459
|
|
|
458
460
|
return transform
|
|
459
461
|
|
|
@@ -608,7 +610,7 @@ def read_url(
|
|
|
608
610
|
encoding: str = 'utf-8',
|
|
609
611
|
) -> Any:
|
|
610
612
|
"""Read an HTTP location and return its content."""
|
|
611
|
-
from urllib.request import Request, urlopen
|
|
613
|
+
from urllib.request import Request, urlopen # noqa: PLC0415
|
|
612
614
|
|
|
613
615
|
if http_cache is not None:
|
|
614
616
|
cached_content = http_cache.get_(url, encoding)
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|