mkdocs-include-markdown-plugin 7.2.0__tar.gz → 7.2.2__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 (16) hide show
  1. {mkdocs_include_markdown_plugin-7.2.0 → mkdocs_include_markdown_plugin-7.2.2}/LICENSE +1 -1
  2. {mkdocs_include_markdown_plugin-7.2.0 → mkdocs_include_markdown_plugin-7.2.2}/PKG-INFO +25 -72
  3. {mkdocs_include_markdown_plugin-7.2.0 → mkdocs_include_markdown_plugin-7.2.2}/README.md +24 -71
  4. {mkdocs_include_markdown_plugin-7.2.0 → mkdocs_include_markdown_plugin-7.2.2}/pyproject.toml +1 -1
  5. {mkdocs_include_markdown_plugin-7.2.0 → mkdocs_include_markdown_plugin-7.2.2}/src/mkdocs_include_markdown_plugin/directive.py +9 -8
  6. {mkdocs_include_markdown_plugin-7.2.0 → mkdocs_include_markdown_plugin-7.2.2}/src/mkdocs_include_markdown_plugin/event.py +7 -6
  7. {mkdocs_include_markdown_plugin-7.2.0 → mkdocs_include_markdown_plugin-7.2.2}/src/mkdocs_include_markdown_plugin/process.py +20 -17
  8. {mkdocs_include_markdown_plugin-7.2.0 → mkdocs_include_markdown_plugin-7.2.2}/.gitignore +0 -0
  9. {mkdocs_include_markdown_plugin-7.2.0 → mkdocs_include_markdown_plugin-7.2.2}/src/mkdocs_include_markdown_plugin/__init__.py +0 -0
  10. {mkdocs_include_markdown_plugin-7.2.0 → mkdocs_include_markdown_plugin-7.2.2}/src/mkdocs_include_markdown_plugin/cache.py +0 -0
  11. {mkdocs_include_markdown_plugin-7.2.0 → mkdocs_include_markdown_plugin-7.2.2}/src/mkdocs_include_markdown_plugin/config.py +0 -0
  12. {mkdocs_include_markdown_plugin-7.2.0 → mkdocs_include_markdown_plugin-7.2.2}/src/mkdocs_include_markdown_plugin/files_watcher.py +0 -0
  13. {mkdocs_include_markdown_plugin-7.2.0 → mkdocs_include_markdown_plugin-7.2.2}/src/mkdocs_include_markdown_plugin/logger.py +0 -0
  14. {mkdocs_include_markdown_plugin-7.2.0 → mkdocs_include_markdown_plugin-7.2.2}/src/mkdocs_include_markdown_plugin/placeholders.py +0 -0
  15. {mkdocs_include_markdown_plugin-7.2.0 → mkdocs_include_markdown_plugin-7.2.2}/src/mkdocs_include_markdown_plugin/plugin.py +0 -0
  16. {mkdocs_include_markdown_plugin-7.2.0 → mkdocs_include_markdown_plugin-7.2.2}/src/mkdocs_include_markdown_plugin/py.typed +0 -0
@@ -187,7 +187,7 @@
187
187
  same "printed page" as the copyright notice for easier
188
188
  identification within third-party archives.
189
189
 
190
- Copyright 2017-2025 Joe Rickerby and contributors
190
+ Copyright 2017-2026 Joe Rickerby and contributors
191
191
 
192
192
  Licensed under the Apache License, Version 2.0 (the "License");
193
193
  you may not use this file except in compliance with the License.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: mkdocs-include-markdown-plugin
3
- Version: 7.2.0
3
+ Version: 7.2.2
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
@@ -181,6 +181,8 @@ plugins:
181
181
  This plugin provides two directives, one to include Markdown files and another
182
182
  to include files of any type.
183
183
 
184
+ #### Common arguments
185
+
184
186
  Paths of included files can be either:
185
187
 
186
188
  - URLs to include remote content.
@@ -199,34 +201,27 @@ single `'` quotes, which can be escaped prepending them a `\` character as
199
201
  The arguments **start** and **end** may contain usual (Python-style) escape
200
202
  sequences like `\n` to match against newlines.
201
203
 
202
- <!-- mdpo-disable-next-line -->
203
-
204
- #### **`include-markdown`**
205
-
206
- Includes Markdown files content, optionally using two delimiters to filter the
207
- content to include.
208
-
209
- - <a name="include-markdown_start" href="#include-markdown_start">#</a>
204
+ - <a name="include_start" href="#include_start">#</a>
210
205
  **start**: Delimiter that marks the beginning of the content to include.
211
- - <a name="include-markdown_end" href="#include-markdown_end">#</a>
206
+ - <a name="include_end" href="#include_end">#</a>
212
207
  **end**: Delimiter that marks the end of the content to include.
213
- - <a name="include-markdown_preserve-includer-indent" href="#include-markdown_preserve-includer-indent">#</a>
208
+ - <a name="include_preserve-includer-indent" href="#include_preserve-includer-indent">#</a>
214
209
  **preserve-includer-indent** (_true_): When this option is enabled (default),
215
210
  every line of the content to include is indented with the same number of
216
211
  spaces used to indent the includer `{% %}` template. Possible values are
217
212
  `true` and `false`.
218
- - <a name="include-markdown_dedent" href="#include-markdown_dedent">#</a>
213
+ - <a name="include_dedent" href="#include_dedent">#</a>
219
214
  **dedent** (_false_): If enabled, the included content will be dedented.
220
- - <a name="include-markdown_exclude" href="#include-markdown_exclude">#</a>
215
+ - <a name="include_exclude" href="#include_exclude">#</a>
221
216
  **exclude**: Specify with a glob which files should be ignored. Only useful
222
217
  when passing globs to include multiple files.
223
- - <a name="include-markdown_trailing-newlines" href="#include-markdown_trailing-newlines">#</a>
218
+ - <a name="include_trailing-newlines" href="#include_trailing-newlines">#</a>
224
219
  **trailing-newlines** (_true_): When this option is disabled, the trailing newlines
225
220
  found in the content to include are stripped. Possible values are `true` and `false`.
226
- - <a name="include-markdown_recursive" href="#include-markdown_recursive">#</a>
221
+ - <a name="include_recursive" href="#include_recursive">#</a>
227
222
  **recursive** (_true_): When this option is disabled, included files are not
228
223
  processed for recursive includes. Possible values are `true` and `false`.
229
- - <a name="include-markdown_order" href="#include-markdown_order">#</a>
224
+ - <a name="include_order" href="#include_order">#</a>
230
225
  **order** (_'alpha-path'_): Define the order in which multiple files are included
231
226
  when using globs. Possible values are:
232
227
  - A combination of an optional order type and an optional order by separated
@@ -241,20 +236,28 @@ content to include.
241
236
  - `'path'` (default): Order by full file path.
242
237
  - `'name'`: Order by file name only.
243
238
  - `'extension'`: Order by file extension.
244
- - A combination of an optional prefix hyphen to denote ascending order and
245
- one of the following values in the form `[-]<value>` where `<value>` is one of:
239
+ - A combination of an optional prefix hyphen to denote ascending order and one
240
+ of the following values in the form `[-]<value>` where `<value>` is one of:
246
241
  - `'size'`: Order by file size.
247
242
  - `'mtime'`: Order by file modification time.
248
243
  - `'ctime'`: Order by file creation time (or the last metadata change time
249
244
  on Unix systems).
250
245
  - `'atime'`: Order by file last access time.
246
+ - `'system'`: Order provided by the operating system. This is the same as not
247
+ specifying any order and relying on the default order of the filesystem.
248
+ This may be different between operating systems, so use it with care.
251
249
  - `'random'`: Random order.
252
- - `'system'`: Order provided by the operating system. This is the same as not
253
- specifying any order and relying on the default order of the filesystem. This
254
- may be different between operating systems, so use it with care.
255
- - <a name="include-markdown_encoding" href="#include-markdown_encoding">#</a>
250
+ - <a name="include_encoding" href="#include_encoding">#</a>
256
251
  **encoding** (_'utf-8'_): Specify the encoding of the included file.
257
252
  If not defined `'utf-8'` will be used.
253
+
254
+ <!-- mdpo-disable-next-line -->
255
+
256
+ #### **`include-markdown`**
257
+
258
+ Includes Markdown files content, optionally using two delimiters to filter the
259
+ content to include.
260
+
258
261
  - <a name="include-markdown_rewrite-relative-urls" href="#include-markdown_rewrite-relative-urls">#</a>
259
262
  **rewrite-relative-urls** (_true_): When this option is enabled (default),
260
263
  Markdown links and images in the content that are specified by a relative URL
@@ -331,56 +334,6 @@ content to include.
331
334
 
332
335
  Includes the content of a file or a group of files.
333
336
 
334
- - <a name="include_start" href="#include_start">#</a>
335
- **start**: Delimiter that marks the beginning of the content to include.
336
- - <a name="include_end" href="#include_end">#</a>
337
- **end**: Delimiter that marks the end of the content to include.
338
- - <a name="include_preserve-includer-indent" href="#include_preserve-includer-indent">#</a>
339
- **preserve-includer-indent** (_true_): When this option is enabled (default),
340
- every line of the content to include is indented with the same number of
341
- spaces used to indent the includer `{% %}` template. Possible values are
342
- `true` and `false`.
343
- - <a name="include_dedent" href="#include_dedent">#</a>
344
- **dedent** (_false_): If enabled, the included content will be dedented.
345
- - <a name="include_exclude" href="#include_exclude">#</a>
346
- **exclude**: Specify with a glob which files should be ignored. Only useful
347
- when passing globs to include multiple files.
348
- - <a name="include_trailing-newlines" href="#include_trailing-newlines">#</a>
349
- **trailing-newlines** (_true_): When this option is disabled, the trailing newlines
350
- found in the content to include are stripped. Possible values are `true` and `false`.
351
- - <a name="include_recursive" href="#include_recursive">#</a>
352
- **recursive** (_true_): When this option is disabled, included files are not
353
- processed for recursive includes. Possible values are `true` and `false`.
354
- - <a name="include_order" href="#include_order">#</a>
355
- **order** (_'alpha-path'_): Define the order in which multiple files are included
356
- when using globs. Possible values are:
357
- - A combination of an optional order type and an optional order by separated
358
- by a hyphen (`-`), and optionally prefixed by a hyphen (`-`) to indicate
359
- ascending order. If an order type or an order by is not specified, the defaults
360
- are used. It follows the form:
361
- `[-]<order_type>-<order_by>` where:
362
- - **Order type**:
363
- - `'alpha'` (default): Alphabetical order.
364
- - `'natural'`: Natural order, so that e.g. `file2.md` comes before `file10.md`.
365
- - **Order by**:
366
- - `'path'` (default): Order by full file path.
367
- - `'name'`: Order by file name only.
368
- - `'extension'`: Order by file extension.
369
- - A combination of an optional prefix hyphen to denote ascending order and
370
- one of the following values in the form `[-]<value>` where `<value>` is one of:
371
- - `'size'`: Order by file size.
372
- - `'mtime'`: Order by file modification time.
373
- - `'ctime'`: Order by file creation time (or the last metadata change time
374
- on Unix systems).
375
- - `'atime'`: Order by file last access time.
376
- - `'random'`: Random order.
377
- - `'system'`: Order provided by the operating system. This is the same as not
378
- specifying any order and relying on the default order of the filesystem. This
379
- may be different between operating systems, so use it with care.
380
- - <a name="include_encoding" href="#include_encoding">#</a>
381
- **encoding** (_'utf-8'_): Specify the encoding of the included file.
382
- If not defined `'utf-8'` will be used.
383
-
384
337
  ##### Examples
385
338
 
386
339
  ```jinja
@@ -146,6 +146,8 @@ plugins:
146
146
  This plugin provides two directives, one to include Markdown files and another
147
147
  to include files of any type.
148
148
 
149
+ #### Common arguments
150
+
149
151
  Paths of included files can be either:
150
152
 
151
153
  - URLs to include remote content.
@@ -164,34 +166,27 @@ single `'` quotes, which can be escaped prepending them a `\` character as
164
166
  The arguments **start** and **end** may contain usual (Python-style) escape
165
167
  sequences like `\n` to match against newlines.
166
168
 
167
- <!-- mdpo-disable-next-line -->
168
-
169
- #### **`include-markdown`**
170
-
171
- Includes Markdown files content, optionally using two delimiters to filter the
172
- content to include.
173
-
174
- - <a name="include-markdown_start" href="#include-markdown_start">#</a>
169
+ - <a name="include_start" href="#include_start">#</a>
175
170
  **start**: Delimiter that marks the beginning of the content to include.
176
- - <a name="include-markdown_end" href="#include-markdown_end">#</a>
171
+ - <a name="include_end" href="#include_end">#</a>
177
172
  **end**: Delimiter that marks the end of the content to include.
178
- - <a name="include-markdown_preserve-includer-indent" href="#include-markdown_preserve-includer-indent">#</a>
173
+ - <a name="include_preserve-includer-indent" href="#include_preserve-includer-indent">#</a>
179
174
  **preserve-includer-indent** (_true_): When this option is enabled (default),
180
175
  every line of the content to include is indented with the same number of
181
176
  spaces used to indent the includer `{% %}` template. Possible values are
182
177
  `true` and `false`.
183
- - <a name="include-markdown_dedent" href="#include-markdown_dedent">#</a>
178
+ - <a name="include_dedent" href="#include_dedent">#</a>
184
179
  **dedent** (_false_): If enabled, the included content will be dedented.
185
- - <a name="include-markdown_exclude" href="#include-markdown_exclude">#</a>
180
+ - <a name="include_exclude" href="#include_exclude">#</a>
186
181
  **exclude**: Specify with a glob which files should be ignored. Only useful
187
182
  when passing globs to include multiple files.
188
- - <a name="include-markdown_trailing-newlines" href="#include-markdown_trailing-newlines">#</a>
183
+ - <a name="include_trailing-newlines" href="#include_trailing-newlines">#</a>
189
184
  **trailing-newlines** (_true_): When this option is disabled, the trailing newlines
190
185
  found in the content to include are stripped. Possible values are `true` and `false`.
191
- - <a name="include-markdown_recursive" href="#include-markdown_recursive">#</a>
186
+ - <a name="include_recursive" href="#include_recursive">#</a>
192
187
  **recursive** (_true_): When this option is disabled, included files are not
193
188
  processed for recursive includes. Possible values are `true` and `false`.
194
- - <a name="include-markdown_order" href="#include-markdown_order">#</a>
189
+ - <a name="include_order" href="#include_order">#</a>
195
190
  **order** (_'alpha-path'_): Define the order in which multiple files are included
196
191
  when using globs. Possible values are:
197
192
  - A combination of an optional order type and an optional order by separated
@@ -206,20 +201,28 @@ content to include.
206
201
  - `'path'` (default): Order by full file path.
207
202
  - `'name'`: Order by file name only.
208
203
  - `'extension'`: Order by file extension.
209
- - A combination of an optional prefix hyphen to denote ascending order and
210
- one of the following values in the form `[-]<value>` where `<value>` is one of:
204
+ - A combination of an optional prefix hyphen to denote ascending order and one
205
+ of the following values in the form `[-]<value>` where `<value>` is one of:
211
206
  - `'size'`: Order by file size.
212
207
  - `'mtime'`: Order by file modification time.
213
208
  - `'ctime'`: Order by file creation time (or the last metadata change time
214
209
  on Unix systems).
215
210
  - `'atime'`: Order by file last access time.
211
+ - `'system'`: Order provided by the operating system. This is the same as not
212
+ specifying any order and relying on the default order of the filesystem.
213
+ This may be different between operating systems, so use it with care.
216
214
  - `'random'`: Random order.
217
- - `'system'`: Order provided by the operating system. This is the same as not
218
- specifying any order and relying on the default order of the filesystem. This
219
- may be different between operating systems, so use it with care.
220
- - <a name="include-markdown_encoding" href="#include-markdown_encoding">#</a>
215
+ - <a name="include_encoding" href="#include_encoding">#</a>
221
216
  **encoding** (_'utf-8'_): Specify the encoding of the included file.
222
217
  If not defined `'utf-8'` will be used.
218
+
219
+ <!-- mdpo-disable-next-line -->
220
+
221
+ #### **`include-markdown`**
222
+
223
+ Includes Markdown files content, optionally using two delimiters to filter the
224
+ content to include.
225
+
223
226
  - <a name="include-markdown_rewrite-relative-urls" href="#include-markdown_rewrite-relative-urls">#</a>
224
227
  **rewrite-relative-urls** (_true_): When this option is enabled (default),
225
228
  Markdown links and images in the content that are specified by a relative URL
@@ -296,56 +299,6 @@ content to include.
296
299
 
297
300
  Includes the content of a file or a group of files.
298
301
 
299
- - <a name="include_start" href="#include_start">#</a>
300
- **start**: Delimiter that marks the beginning of the content to include.
301
- - <a name="include_end" href="#include_end">#</a>
302
- **end**: Delimiter that marks the end of the content to include.
303
- - <a name="include_preserve-includer-indent" href="#include_preserve-includer-indent">#</a>
304
- **preserve-includer-indent** (_true_): When this option is enabled (default),
305
- every line of the content to include is indented with the same number of
306
- spaces used to indent the includer `{% %}` template. Possible values are
307
- `true` and `false`.
308
- - <a name="include_dedent" href="#include_dedent">#</a>
309
- **dedent** (_false_): If enabled, the included content will be dedented.
310
- - <a name="include_exclude" href="#include_exclude">#</a>
311
- **exclude**: Specify with a glob which files should be ignored. Only useful
312
- when passing globs to include multiple files.
313
- - <a name="include_trailing-newlines" href="#include_trailing-newlines">#</a>
314
- **trailing-newlines** (_true_): When this option is disabled, the trailing newlines
315
- found in the content to include are stripped. Possible values are `true` and `false`.
316
- - <a name="include_recursive" href="#include_recursive">#</a>
317
- **recursive** (_true_): When this option is disabled, included files are not
318
- processed for recursive includes. Possible values are `true` and `false`.
319
- - <a name="include_order" href="#include_order">#</a>
320
- **order** (_'alpha-path'_): Define the order in which multiple files are included
321
- when using globs. Possible values are:
322
- - A combination of an optional order type and an optional order by separated
323
- by a hyphen (`-`), and optionally prefixed by a hyphen (`-`) to indicate
324
- ascending order. If an order type or an order by is not specified, the defaults
325
- are used. It follows the form:
326
- `[-]<order_type>-<order_by>` where:
327
- - **Order type**:
328
- - `'alpha'` (default): Alphabetical order.
329
- - `'natural'`: Natural order, so that e.g. `file2.md` comes before `file10.md`.
330
- - **Order by**:
331
- - `'path'` (default): Order by full file path.
332
- - `'name'`: Order by file name only.
333
- - `'extension'`: Order by file extension.
334
- - A combination of an optional prefix hyphen to denote ascending order and
335
- one of the following values in the form `[-]<value>` where `<value>` is one of:
336
- - `'size'`: Order by file size.
337
- - `'mtime'`: Order by file modification time.
338
- - `'ctime'`: Order by file creation time (or the last metadata change time
339
- on Unix systems).
340
- - `'atime'`: Order by file last access time.
341
- - `'random'`: Random order.
342
- - `'system'`: Order provided by the operating system. This is the same as not
343
- specifying any order and relying on the default order of the filesystem. This
344
- may be different between operating systems, so use it with care.
345
- - <a name="include_encoding" href="#include_encoding">#</a>
346
- **encoding** (_'utf-8'_): Specify the encoding of the included file.
347
- If not defined `'utf-8'` will be used.
348
-
349
302
  ##### Examples
350
303
 
351
304
  ```jinja
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "mkdocs-include-markdown-plugin"
3
- version = "7.2.0"
3
+ version = "7.2.2"
4
4
  description = "Mkdocs Markdown includer plugin."
5
5
  readme = "README.md"
6
6
  license = "Apache-2.0"
@@ -140,7 +140,7 @@ def _maybe_arguments_iter(arguments_string: str) -> Iterable[str]:
140
140
  inside_string = False
141
141
  escaping = False
142
142
  opening_argument = False # whether we are at the beginning of an argument
143
- current_value = ''
143
+ current_value: list[str] = []
144
144
 
145
145
  for c in arguments_string:
146
146
  if inside_string:
@@ -153,24 +153,25 @@ def _maybe_arguments_iter(arguments_string: str) -> Iterable[str]:
153
153
  else:
154
154
  escaping = False
155
155
  elif c == '=':
156
+ current_value_str = ''.join(current_value)
156
157
  new_current_value = ''
157
- for ch in reversed(current_value):
158
+ for ch in reversed(current_value_str):
158
159
  if ch in string.whitespace:
159
- current_value = new_current_value[::-1]
160
+ current_value_str = new_current_value[::-1]
160
161
  break
161
162
  new_current_value += ch
162
- yield current_value
163
- current_value = ''
163
+ yield current_value_str
164
+ current_value = []
164
165
  opening_argument = True
165
166
  elif opening_argument:
166
167
  opening_argument = False
167
168
  if c in ('"', "'"):
168
169
  current_string_opening = c
169
170
  inside_string = True
170
- current_value += c
171
- current_value += c
171
+ current_value.append(c)
172
+ current_value.append(c)
172
173
  else:
173
- current_value += c
174
+ current_value.append(c)
174
175
 
175
176
 
176
177
  def warn_invalid_directive_arguments(
@@ -545,7 +545,7 @@ def get_file_content( # noqa: PLR0913, PLR0915
545
545
  # but they have been specified, so the warning(s) must be raised
546
546
  expected_but_any_found = [start is not None, end is not None]
547
547
 
548
- text_to_include = ''
548
+ text_to_include_parts = []
549
549
  for file_path in file_paths_to_include:
550
550
  if process.is_url(filename):
551
551
  new_text_to_include = process.read_url(
@@ -621,11 +621,10 @@ def get_file_content( # noqa: PLR0913, PLR0915
621
621
  new_text_to_include
622
622
  ):
623
623
  lines = new_text_to_include.splitlines(keepends=True)
624
- new_text_to_include = lines[0]
624
+ indented_lines = [lines[0]]
625
625
  for i in range(1, len(lines)):
626
- new_text_to_include += (
627
- filled_includer_indent + lines[i]
628
- )
626
+ indented_lines.append(filled_includer_indent + lines[i])
627
+ new_text_to_include = ''.join(indented_lines)
629
628
 
630
629
  if offset:
631
630
  new_text_to_include = process.increase_headings_offset(
@@ -633,7 +632,9 @@ def get_file_content( # noqa: PLR0913, PLR0915
633
632
  offset=offset + cumulative_heading_offset,
634
633
  )
635
634
 
636
- text_to_include += new_text_to_include
635
+ text_to_include_parts.append(new_text_to_include)
636
+
637
+ text_to_include = ''.join(text_to_include_parts)
637
638
 
638
639
  # warn if expected start or ends haven't been found in included content
639
640
  for i, delimiter_name in enumerate(['start', 'end']):
@@ -174,10 +174,12 @@ def transform_p_by_p_skipping_codeblocks( # noqa: PLR0912, PLR0915
174
174
  _maybe_icodeblock_lines: list[str] = []
175
175
  _previous_line_was_empty = False
176
176
 
177
- lines, current_paragraph = ([], '')
177
+ lines = []
178
+ current_paragraph_lines: list[str] = []
178
179
 
179
180
  def process_current_paragraph() -> None:
180
- lines.extend(func(current_paragraph).splitlines(keepends=True))
181
+ lines.extend(func(''.join(current_paragraph_lines),
182
+ ).splitlines(keepends=True))
181
183
 
182
184
  # The next implementation takes into account that indented code
183
185
  # blocks must be surrounded by newlines as per the CommonMark
@@ -191,25 +193,24 @@ def transform_p_by_p_skipping_codeblocks( # noqa: PLR0912, PLR0915
191
193
  if lstripped_line.startswith(('```', '~~~')):
192
194
  _current_fcodeblock_delimiter = lstripped_line[:3]
193
195
  process_current_paragraph()
194
- current_paragraph = ''
196
+ current_paragraph_lines = []
195
197
  lines.append(line)
196
198
  elif line.startswith(' '):
197
199
  if not lstripped_line or _maybe_icodeblock_lines:
198
200
  # maybe enter indented codeblock
199
201
  _maybe_icodeblock_lines.append(line)
200
202
  else:
201
- current_paragraph += line
203
+ current_paragraph_lines.append(line)
202
204
  elif _maybe_icodeblock_lines:
203
205
  process_current_paragraph()
204
- current_paragraph = ''
206
+ current_paragraph_lines = []
205
207
  if not _previous_line_was_empty:
206
208
  # wasn't an indented code block
207
- for line_ in _maybe_icodeblock_lines:
208
- current_paragraph += line_
209
+ current_paragraph_lines.extend(_maybe_icodeblock_lines)
209
210
  _maybe_icodeblock_lines = []
210
- current_paragraph += line
211
+ current_paragraph_lines.append(line)
211
212
  process_current_paragraph()
212
- current_paragraph = ''
213
+ current_paragraph_lines = []
213
214
  else:
214
215
  # exit indented codeblock
215
216
  for line_ in _maybe_icodeblock_lines:
@@ -217,7 +218,7 @@ def transform_p_by_p_skipping_codeblocks( # noqa: PLR0912, PLR0915
217
218
  _maybe_icodeblock_lines = []
218
219
  lines.append(line)
219
220
  else:
220
- current_paragraph += line
221
+ current_paragraph_lines.append(line)
221
222
  _previous_line_was_empty = not lstripped_line
222
223
  else:
223
224
  lines.append(line)
@@ -230,14 +231,13 @@ def transform_p_by_p_skipping_codeblocks( # noqa: PLR0912, PLR0915
230
231
  if not _previous_line_was_empty:
231
232
  # at EOF
232
233
  process_current_paragraph()
233
- current_paragraph = ''
234
- for line_ in _maybe_icodeblock_lines:
235
- current_paragraph += line_
234
+ current_paragraph_lines = []
235
+ current_paragraph_lines.extend(_maybe_icodeblock_lines)
236
236
  process_current_paragraph()
237
- current_paragraph = ''
237
+ current_paragraph_lines = []
238
238
  else:
239
239
  process_current_paragraph()
240
- current_paragraph = ''
240
+ current_paragraph_lines = []
241
241
  for line_ in _maybe_icodeblock_lines:
242
242
  lines.append(line_)
243
243
  else:
@@ -547,8 +547,11 @@ def sort_paths(paths: list[str], order: OrderOption) -> list[str]:
547
547
  return os.path.splitext(p)[1]
548
548
  elif order_type == 'natural':
549
549
  if order_by == 'extension':
550
- def key(p: str) -> str:
551
- return natural_sort_key(os.path.splitext(p)[1]) # type: ignore
550
+ def key(p: str) -> tuple: # type: ignore
551
+ return (
552
+ natural_sort_key(os.path.splitext(p)[1]),
553
+ natural_sort_key(os.path.basename(p)),
554
+ )
552
555
  elif order_by == 'name':
553
556
  def key(p: str) -> str:
554
557
  return natural_sort_key(os.path.basename(p)) # type: ignore