Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "mkdocs-include-markdown-plugin"
version = "7.2.0"
version = "7.2.1"
description = "Mkdocs Markdown includer plugin."
readme = "README.md"
license = "Apache-2.0"
Expand Down
17 changes: 9 additions & 8 deletions src/mkdocs_include_markdown_plugin/directive.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ def _maybe_arguments_iter(arguments_string: str) -> Iterable[str]:
inside_string = False
escaping = False
opening_argument = False # whether we are at the beginning of an argument
current_value = ''
current_value: list[str] = []

for c in arguments_string:
if inside_string:
Expand All @@ -153,24 +153,25 @@ def _maybe_arguments_iter(arguments_string: str) -> Iterable[str]:
else:
escaping = False
elif c == '=':
current_value_str = ''.join(current_value)
new_current_value = ''
for ch in reversed(current_value):
for ch in reversed(current_value_str):
if ch in string.whitespace:
current_value = new_current_value[::-1]
current_value_str = new_current_value[::-1]
break
new_current_value += ch
yield current_value
current_value = ''
yield current_value_str
current_value = []
opening_argument = True
elif opening_argument:
opening_argument = False
if c in ('"', "'"):
current_string_opening = c
inside_string = True
current_value += c
current_value += c
current_value.append(c)
current_value.append(c)
else:
current_value += c
current_value.append(c)


def warn_invalid_directive_arguments(
Expand Down
13 changes: 7 additions & 6 deletions src/mkdocs_include_markdown_plugin/event.py
Original file line number Diff line number Diff line change
Expand Up @@ -545,7 +545,7 @@ def found_include_markdown_tag( # noqa: PLR0912, PLR0915
# but they have been specified, so the warning(s) must be raised
expected_but_any_found = [start is not None, end is not None]

text_to_include = ''
text_to_include_parts = []
for file_path in file_paths_to_include:
if process.is_url(filename):
new_text_to_include = process.read_url(
Expand Down Expand Up @@ -621,19 +621,20 @@ def found_include_markdown_tag( # noqa: PLR0912, PLR0915
new_text_to_include
):
lines = new_text_to_include.splitlines(keepends=True)
new_text_to_include = lines[0]
indented_lines = [lines[0]]
for i in range(1, len(lines)):
new_text_to_include += (
filled_includer_indent + lines[i]
)
indented_lines.append(filled_includer_indent + lines[i])
new_text_to_include = ''.join(indented_lines)

if offset:
new_text_to_include = process.increase_headings_offset(
new_text_to_include,
offset=offset + cumulative_heading_offset,
)

text_to_include += new_text_to_include
text_to_include_parts.append(new_text_to_include)

text_to_include = ''.join(text_to_include_parts)

# warn if expected start or ends haven't been found in included content
for i, delimiter_name in enumerate(['start', 'end']):
Expand Down
30 changes: 15 additions & 15 deletions src/mkdocs_include_markdown_plugin/process.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,10 +174,12 @@ def transform_p_by_p_skipping_codeblocks( # noqa: PLR0912, PLR0915
_maybe_icodeblock_lines: list[str] = []
_previous_line_was_empty = False

lines, current_paragraph = ([], '')
lines = []
current_paragraph_lines: list[str] = []

def process_current_paragraph() -> None:
lines.extend(func(current_paragraph).splitlines(keepends=True))
lines.extend(func(''.join(current_paragraph_lines),
).splitlines(keepends=True))

# The next implementation takes into account that indented code
# blocks must be surrounded by newlines as per the CommonMark
Expand All @@ -191,33 +193,32 @@ def process_current_paragraph() -> None:
if lstripped_line.startswith(('```', '~~~')):
_current_fcodeblock_delimiter = lstripped_line[:3]
process_current_paragraph()
current_paragraph = ''
current_paragraph_lines = []
lines.append(line)
elif line.startswith(' '):
if not lstripped_line or _maybe_icodeblock_lines:
# maybe enter indented codeblock
_maybe_icodeblock_lines.append(line)
else:
current_paragraph += line
current_paragraph_lines.append(line)
elif _maybe_icodeblock_lines:
process_current_paragraph()
current_paragraph = ''
current_paragraph_lines = []
if not _previous_line_was_empty:
# wasn't an indented code block
for line_ in _maybe_icodeblock_lines:
current_paragraph += line_
current_paragraph_lines.extend(_maybe_icodeblock_lines)
_maybe_icodeblock_lines = []
current_paragraph += line
current_paragraph_lines.append(line)
process_current_paragraph()
current_paragraph = ''
current_paragraph_lines = []
else:
# exit indented codeblock
for line_ in _maybe_icodeblock_lines:
lines.append(line_)
_maybe_icodeblock_lines = []
lines.append(line)
else:
current_paragraph += line
current_paragraph_lines.append(line)
_previous_line_was_empty = not lstripped_line
else:
lines.append(line)
Expand All @@ -230,14 +231,13 @@ def process_current_paragraph() -> None:
if not _previous_line_was_empty:
# at EOF
process_current_paragraph()
current_paragraph = ''
for line_ in _maybe_icodeblock_lines:
current_paragraph += line_
current_paragraph_lines = []
current_paragraph_lines.extend(_maybe_icodeblock_lines)
process_current_paragraph()
current_paragraph = ''
current_paragraph_lines = []
else:
process_current_paragraph()
current_paragraph = ''
current_paragraph_lines = []
for line_ in _maybe_icodeblock_lines:
lines.append(line_)
else:
Expand Down