Skip to content

Commit 7a7cb71

Browse files
authored
Add recursive argument to include-markdown directive (#218)
1 parent f7ebed6 commit 7a7cb71

File tree

9 files changed

+153
-58
lines changed

9 files changed

+153
-58
lines changed

README.md

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,9 @@ content to include.
155155
- <a name="include-markdown_trailing-newlines" href="#include-markdown_trailing-newlines">#</a>
156156
**trailing-newlines** (_true_): When this option is disabled, the trailing newlines
157157
found in the content to include are stripped. Possible values are `true` and `false`.
158+
- <a name="include-markdown_recursive" href="#include-markdown_recursive">#</a>
159+
**recursive** (_true_): When this option is disabled, included files are not
160+
processed for recursive includes. Possible values are `true` and `false`.
158161
- <a name="include-markdown_encoding" href="#include-markdown_encoding">#</a>
159162
**encoding** (_utf-8_): Specify the encoding of the included file.
160163
If not defined `utf-8` will be used.
@@ -243,12 +246,12 @@ Includes the content of a file or a group of files.
243246
- <a name="include_trailing-newlines" href="#include_trailing-newlines">#</a>
244247
**trailing-newlines** (_true_): When this option is disabled, the trailing newlines
245248
found in the content to include are stripped. Possible values are `true` and `false`.
249+
- <a name="include_recursive" href="#include_recursive">#</a>
250+
**recursive** (_true_): When this option is disabled, included files are not
251+
processed for recursive includes. Possible values are `true` and `false`.
246252
- <a name="include_encoding" href="#include_encoding">#</a>
247253
**encoding** (_utf-8_): Specify the encoding of the included file.
248254
If not defined `utf-8` will be used.
249-
- <a name="recursive" href="#include_recursive">#</a>
250-
**recursive** (_true_): When this option is disabled, included files are not
251-
processed for recursive includes. Possible values are `true` and `false`.
252255

253256
##### Examples
254257

@@ -275,8 +278,9 @@ Includes the content of a file or a group of files.
275278

276279
## Acknowledgment
277280

278-
- Joe Rickerby and contributors for
279-
[giving me the permissions][cibuildwheel-470] to separate this plugin from the
281+
- [Joe Rickerby] and [contributors] for
282+
[giving me the permissions][cibuildwheel-470] to
283+
[separate this plugin][cibuildwheel-475] from the
280284
documentation of [cibuildwheel][cibuildwheel-repo-link].
281285

282286
[Bash wildcard globs]: https://facelessuser.github.io/wcmatch/glob/#syntax
@@ -293,7 +297,10 @@ Includes the content of a file or a group of files.
293297
[license-link]: https://github.com/mondeja/mkdocs-include-markdown-plugin/blob/master/LICENSE
294298
[platformdirs]: https://pypi.org/project/platformdirs/
295299
[cibuildwheel-470]: https://github.com/pypa/cibuildwheel/issues/470
300+
[cibuildwheel-475]: https://github.com/pypa/cibuildwheel/pull/475
296301
[cibuildwheel-repo-link]: https://github.com/pypa/cibuildwheel
297302
[es-readme-link]: https://github.com/mondeja/mkdocs-include-markdown-plugin/blob/master/locale/es/README.md
298303
[fr-readme-link]: https://github.com/mondeja/mkdocs-include-markdown-plugin/blob/master/locale/fr/README.md
299304
[`docs_dir`]: https://www.mkdocs.org/user-guide/configuration/#docs_dir
305+
[Joe Rickerby]: https://github.com/joerick
306+
[contributors]: https://github.com/mondeja/mkdocs-include-markdown-plugin/graphs/contributors

locale/es/README.md

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,10 @@ href="#include-markdown_trailing-newlines">#</a> **trailing-newlines**
144144
(*true*): Cuando esta opción está deshabilitada, los saltos de línea finales que
145145
se encuentran en el contenido a incluir se eliminan. Los valores posibles son
146146
`true` y `false`.
147+
- <a name="include-markdown_recursive" href="#include-markdown_recursive">#</a>
148+
**recursive** (*true*): Cuando esta opción está deshabilitada, los archivos
149+
incluidos no son procesados para incluir de forma recursiva. Los valores
150+
posibles son `true` y `false`.
147151
- <a name="include-markdown_encoding" href="#include-markdown_encoding">#</a>
148152
**encoding** (*utf-8*): Especifica la codificación del archivo incluído. Si no
149153
se define, se usará `utf-8`.
@@ -234,13 +238,13 @@ globs para incluir múltiples archivos.
234238
**trailing-newlines** (*true*): Cuando esta opción está deshabilitada, los
235239
saltos de línea finales que se encuentran en el contenido a incluir se eliminan.
236240
Los valores posibles son `true` y `false`.
241+
- <a name="include_recursive" href="#include_recursive">#</a> **recursive**
242+
(*true*): Cuando esta opción está deshabilitada, los archivos incluidos no son
243+
procesados para incluir de forma recursiva. Los valores posibles son `true` y
244+
`false`.
237245
- <a name="include_encoding" href="#include_encoding">#</a> **encoding**
238246
(*utf-8*): Especifica la codificación del archivo incluído. Si no se define,
239247
se usará `utf-8`.
240-
- <a name="recursive" href="#include_recursive">#</a> **recursive** (*true*):
241-
Cuando esta opción está deshabilitada, los archivos incluidos no son
242-
procesados para incluir de forma recursiva. Los valores posibles son `true` y
243-
`false`.
244248

245249
##### Ejemplos
246250

@@ -267,8 +271,8 @@ procesados para incluir de forma recursiva. Los valores posibles son `true` y
267271

268272
## Agradecimiento
269273

270-
- Joe Rickerby y contribuidores por [darme los permisos][cibuildwheel-470] para
271-
separar este plugin de la documentación de
274+
- [Joe Rickerby] y [contribuidores] por [darme los permisos][cibuildwheel-470]
275+
para [separar este plugin][cibuildwheel-475] de la documentación de
272276
[cibuildwheel][cibuildwheel-repo-link].
273277

274278
[Patrones glob de Bash]: https://facelessuser.github.io/wcmatch/glob/#syntax
@@ -282,7 +286,10 @@ separar este plugin de la documentación de
282286
[license-link]: https://github.com/mondeja/mkdocs-include-markdown-plugin/blob/master/LICENSE
283287
[platformdirs]: https://pypi.org/project/platformdirs/
284288
[cibuildwheel-470]: https://github.com/pypa/cibuildwheel/issues/470
289+
[cibuildwheel-475]: https://github.com/pypa/cibuildwheel/pull/475
285290
[cibuildwheel-repo-link]: https://github.com/pypa/cibuildwheel
286291
[es-readme-link]: https://github.com/mondeja/mkdocs-include-markdown-plugin/blob/master/locale/es/README.md
287292
[fr-readme-link]: https://github.com/mondeja/mkdocs-include-markdown-plugin/blob/master/locale/fr/README.md
288293
[`docs_dir`]: https://www.mkdocs.org/user-guide/configuration/#docs_dir
294+
[Joe Rickerby]: https://github.com/joerick
295+
[contribuidores]: https://github.com/mondeja/mkdocs-include-markdown-plugin/graphs/contributors

locale/es/README.md.po

Lines changed: 37 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,13 @@ msgid "Acknowledgment"
3131
msgstr "Agradecimiento"
3232

3333
msgid ""
34-
"Joe Rickerby and contributors for [giving me the "
35-
"permissions][cibuildwheel-470] to separate this plugin from the "
36-
"documentation of [cibuildwheel][cibuildwheel-repo-link]."
34+
"[Joe Rickerby] and [contributors] for [giving me the "
35+
"permissions][cibuildwheel-470] to [separate this plugin][cibuildwheel-475] "
36+
"from the documentation of [cibuildwheel][cibuildwheel-repo-link]."
3737
msgstr ""
38-
"Joe Rickerby y contribuidores por [darme los permisos][cibuildwheel-470] "
39-
"para separar este plugin de la documentación de [cibuildwheel][cibuildwheel-"
40-
"repo-link]."
38+
"[Joe Rickerby] y [contribuidores] por [darme los permisos][cibuildwheel-470]"
39+
" para [separar este plugin][cibuildwheel-475] de la documentación de "
40+
"[cibuildwheel][cibuildwheel-repo-link]."
4141

4242
msgid ""
4343
"[pypi-version-badge-link]: https://img.shields.io/pypi/v/mkdocs-include-"
@@ -408,11 +408,35 @@ msgid "[pypi-link]: https://pypi.org/project/mkdocs-include-markdown-plugin"
408408
msgstr "[pypi-link]: https://pypi.org/project/mkdocs-include-markdown-plugin"
409409

410410
msgid ""
411-
"<a name=\"recursive\" href=\"#include_recursive\">#</a> **recursive** "
412-
"(*true*): When this option is disabled, included files are not processed for"
413-
" recursive includes. Possible values are `true` and `false`."
411+
"<a name=\"include_recursive\" href=\"#include_recursive\">#</a> "
412+
"**recursive** (*true*): When this option is disabled, included files are not"
413+
" processed for recursive includes. Possible values are `true` and `false`."
414414
msgstr ""
415-
"<a name=\"recursive\" href=\"#include_recursive\">#</a> **recursive** "
416-
"(*true*): Cuando esta opción está deshabilitada, los archivos incluidos no "
417-
"son procesados para incluir de forma recursiva. Los valores posibles son "
418-
"`true` y `false`."
415+
"<a name=\"include_recursive\" href=\"#include_recursive\">#</a> "
416+
"**recursive** (*true*): Cuando esta opción está deshabilitada, los archivos "
417+
"incluidos no son procesados para incluir de forma recursiva. Los valores "
418+
"posibles son `true` y `false`."
419+
420+
msgid ""
421+
"<a name=\"include-markdown_recursive\" href=\"#include-"
422+
"markdown_recursive\">#</a> **recursive** (*true*): When this option is "
423+
"disabled, included files are not processed for recursive includes. Possible "
424+
"values are `true` and `false`."
425+
msgstr ""
426+
"<a name=\"include-markdown_recursive\" href=\"#include-"
427+
"markdown_recursive\">#</a> **recursive** (*true*): Cuando esta opción está "
428+
"deshabilitada, los archivos incluidos no son procesados para incluir de "
429+
"forma recursiva. Los valores posibles son `true` y `false`."
430+
431+
msgid "[Joe Rickerby]: https://github.com/joerick"
432+
msgstr "[Joe Rickerby]: https://github.com/joerick"
433+
434+
msgid ""
435+
"[contributors]: https://github.com/mondeja/mkdocs-include-markdown-"
436+
"plugin/graphs/contributors"
437+
msgstr ""
438+
"[contribuidores]: https://github.com/mondeja/mkdocs-include-markdown-"
439+
"plugin/graphs/contributors"
440+
441+
msgid "[cibuildwheel-475]: https://github.com/pypa/cibuildwheel/pull/475"
442+
msgstr "[cibuildwheel-475]: https://github.com/pypa/cibuildwheel/pull/475"

locale/fr/README.md

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,10 @@ href="#include-markdown_trailing-newlines">#</a> **trailing-newlines**
144144
(*true*): Lorsque cette option est désactivée, les nouvelles lignes de fin
145145
trouvées dans le contenu à inclure sont supprimées. Les valeurs possibles sont
146146
`true` et `false`.
147+
- <a name="include-markdown_recursive" href="#include-markdown_recursive">#</a>
148+
**recursive** (*true*): Lorsque cette option est désactivée, les fichiers
149+
inclus ne sont pas traités pour des inclusions récursives. Les valeurs possibles
150+
sont `true` et `false`.
147151
- <a name="include-markdown_encoding" href="#include-markdown_encoding">#</a>
148152
**encoding** (*utf-8*): Spécifiez l'encodage du fichier inclus. S'il n'est pas
149153
défini, `utf-8` sera utilisé.
@@ -233,12 +237,13 @@ passage de globs pour inclure plusieurs fichiers.
233237
**trailing-newlines** (*true*): Lorsque cette option est désactivée, les
234238
nouvelles lignes de fin trouvées dans le contenu à inclure sont supprimées. Les
235239
valeurs possibles sont `true` et `false`.
240+
- <a name="include_recursive" href="#include_recursive">#</a> **recursive**
241+
(*true*): Lorsque cette option est désactivée, les fichiers inclus ne sont pas
242+
traités pour des inclusions récursives. Les valeurs possibles sont `true` et
243+
`false`.
236244
- <a name="include_encoding" href="#include_encoding">#</a> **encoding**
237245
(*utf-8*): Spécifiez l'encodage du fichier inclus. S'il n'est pas défini,
238246
`utf-8` sera utilisé.
239-
- <a name="recursive" href="#include_recursive">#</a> **recursive** (*true*):
240-
Lorsque cette option est désactivée, les fichiers inclus ne sont pas traités
241-
pour des inclusions récursives. Les valeurs possibles sont `true` et `false`.
242247

243248
##### Exemples
244249

@@ -265,9 +270,9 @@ pour des inclusions récursives. Les valeurs possibles sont `true` et `false`.
265270

266271
## Reconnaissance
267272

268-
- Joe Rickerby et des contributeurs pour [m'avoir donné les
269-
autorisations][cibuildwheel-470] pour séparer ce plugin de la documentation de
270-
[cibuildwheel][cibuildwheel-repo-link].
273+
- [Joe Rickerby] et [des contributeurs] pour [m'avoir donné les
274+
autorisations][cibuildwheel-470] pour [séparer ce plugin][cibuildwheel-475] de
275+
la documentation de [cibuildwheel][cibuildwheel-repo-link].
271276

272277
[Globs génériques Bash]: https://facelessuser.github.io/wcmatch/glob/#syntax
273278
[pypi-link]: https://pypi.org/project/mkdocs-include-markdown-plugin
@@ -280,7 +285,10 @@ autorisations][cibuildwheel-470] pour séparer ce plugin de la documentation de
280285
[license-link]: https://github.com/mondeja/mkdocs-include-markdown-plugin/blob/master/LICENSE
281286
[platformdirs]: https://pypi.org/project/platformdirs/
282287
[cibuildwheel-470]: https://github.com/pypa/cibuildwheel/issues/470
288+
[cibuildwheel-475]: https://github.com/pypa/cibuildwheel/pull/475
283289
[cibuildwheel-repo-link]: https://github.com/pypa/cibuildwheel
284290
[es-readme-link]: https://github.com/mondeja/mkdocs-include-markdown-plugin/blob/master/locale/es/README.md
285291
[fr-readme-link]: https://github.com/mondeja/mkdocs-include-markdown-plugin/blob/master/locale/fr/README.md
286292
[`docs_dir`]: https://www.mkdocs.org/user-guide/configuration/#docs_dir
293+
[Joe Rickerby]: https://github.com/joerick
294+
[des contributeurs]: https://github.com/mondeja/mkdocs-include-markdown-plugin/graphs/contributors

locale/fr/README.md.po

Lines changed: 37 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -44,13 +44,13 @@ msgid "Acknowledgment"
4444
msgstr "Reconnaissance"
4545

4646
msgid ""
47-
"Joe Rickerby and contributors for [giving me the "
48-
"permissions][cibuildwheel-470] to separate this plugin from the "
49-
"documentation of [cibuildwheel][cibuildwheel-repo-link]."
47+
"[Joe Rickerby] and [contributors] for [giving me the "
48+
"permissions][cibuildwheel-470] to [separate this plugin][cibuildwheel-475] "
49+
"from the documentation of [cibuildwheel][cibuildwheel-repo-link]."
5050
msgstr ""
51-
"Joe Rickerby et des contributeurs pour [m'avoir donné les "
52-
"autorisations][cibuildwheel-470] pour séparer ce plugin de la documentation "
53-
"de [cibuildwheel][cibuildwheel-repo-link]."
51+
"[Joe Rickerby] et [des contributeurs] pour [m'avoir donné les "
52+
"autorisations][cibuildwheel-470] pour [séparer ce plugin][cibuildwheel-475] "
53+
"de la documentation de [cibuildwheel][cibuildwheel-repo-link]."
5454

5555
msgid ""
5656
"[pypi-version-badge-link]: https://img.shields.io/pypi/v/mkdocs-include-"
@@ -406,11 +406,35 @@ msgid "[pypi-link]: https://pypi.org/project/mkdocs-include-markdown-plugin"
406406
msgstr "[pypi-link]: https://pypi.org/project/mkdocs-include-markdown-plugin"
407407

408408
msgid ""
409-
"<a name=\"recursive\" href=\"#include_recursive\">#</a> **recursive** "
410-
"(*true*): When this option is disabled, included files are not processed for"
411-
" recursive includes. Possible values are `true` and `false`."
409+
"<a name=\"include_recursive\" href=\"#include_recursive\">#</a> "
410+
"**recursive** (*true*): When this option is disabled, included files are not"
411+
" processed for recursive includes. Possible values are `true` and `false`."
412412
msgstr ""
413-
"<a name=\"recursive\" href=\"#include_recursive\">#</a> **recursive** "
414-
"(*true*): Lorsque cette option est désactivée, les fichiers inclus ne sont "
415-
"pas traités pour des inclusions récursives. Les valeurs possibles sont "
416-
"`true` et `false`."
413+
"<a name=\"include_recursive\" href=\"#include_recursive\">#</a> "
414+
"**recursive** (*true*): Lorsque cette option est désactivée, les fichiers "
415+
"inclus ne sont pas traités pour des inclusions récursives. Les valeurs "
416+
"possibles sont `true` et `false`."
417+
418+
msgid ""
419+
"<a name=\"include-markdown_recursive\" href=\"#include-"
420+
"markdown_recursive\">#</a> **recursive** (*true*): When this option is "
421+
"disabled, included files are not processed for recursive includes. Possible "
422+
"values are `true` and `false`."
423+
msgstr ""
424+
"<a name=\"include-markdown_recursive\" href=\"#include-"
425+
"markdown_recursive\">#</a> **recursive** (*true*): Lorsque cette option est "
426+
"désactivée, les fichiers inclus ne sont pas traités pour des inclusions "
427+
"récursives. Les valeurs possibles sont `true` et `false`."
428+
429+
msgid "[Joe Rickerby]: https://github.com/joerick"
430+
msgstr "[Joe Rickerby]: https://github.com/joerick"
431+
432+
msgid ""
433+
"[contributors]: https://github.com/mondeja/mkdocs-include-markdown-"
434+
"plugin/graphs/contributors"
435+
msgstr ""
436+
"[des contributeurs]: https://github.com/mondeja/mkdocs-include-markdown-"
437+
"plugin/graphs/contributors"
438+
439+
msgid "[cibuildwheel-475]: https://github.com/pypa/cibuildwheel/pull/475"
440+
msgstr "[cibuildwheel-475]: https://github.com/pypa/cibuildwheel/pull/475"

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[project]
22
name = "mkdocs-include-markdown-plugin"
3-
version = "6.1.2"
3+
version = "6.2.0"
44
description = "Mkdocs Markdown includer plugin."
55
readme = "README.md"
66
license = "Apache-2.0"

src/mkdocs_include_markdown_plugin/directive.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -110,9 +110,7 @@ def str_arg(arg: str) -> re.Pattern[str]:
110110
)
111111
}
112112

113-
INCLUDE_MARKDOWN_DIRECTIVE_ARGS = {
114-
key for key in ARGUMENT_REGEXES if key != 'recursive'
115-
}
113+
INCLUDE_MARKDOWN_DIRECTIVE_ARGS = set(ARGUMENT_REGEXES)
116114

117115

118116
def warn_invalid_directive_arguments(

src/mkdocs_include_markdown_plugin/event.py

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -379,7 +379,7 @@ def found_include_markdown_tag( # noqa: PLR0912, PLR0915
379379
[
380380
'rewrite-relative-urls', 'comments',
381381
'preserve-includer-indent', 'dedent',
382-
'trailing-newlines',
382+
'trailing-newlines', 'recursive',
383383
],
384384
defaults,
385385
arguments_string,
@@ -498,16 +498,17 @@ def found_include_markdown_tag( # noqa: PLR0912, PLR0915
498498
expected_but_any_found[i] = False
499499

500500
# nested includes
501-
new_text_to_include = get_file_content(
502-
new_text_to_include,
503-
file_path,
504-
docs_dir,
505-
tags,
506-
defaults,
507-
settings,
508-
files_watcher=files_watcher,
509-
http_cache=http_cache,
510-
)
501+
if bool_options['recursive'].value:
502+
new_text_to_include = get_file_content(
503+
new_text_to_include,
504+
file_path,
505+
docs_dir,
506+
tags,
507+
defaults,
508+
settings,
509+
files_watcher=files_watcher,
510+
http_cache=http_cache,
511+
)
511512

512513
# trailing newlines right stripping
513514
if not bool_options['trailing-newlines'].value:

tests/test_unit/test_nested_includes.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,32 @@
251251
[],
252252
id='include-recursive=false',
253253
),
254+
# recursive inclusion disabled with `include-markdown` directive
255+
pytest.param(
256+
'''# Header
257+
258+
{%
259+
include-markdown "{filepath}"
260+
recursive=false
261+
comments=false
262+
%}''',
263+
'''# Header 2
264+
265+
{% include-markdown "{filepath}" %}
266+
''',
267+
'''# Header 3
268+
269+
This content must not be included.
270+
''',
271+
'''# Header
272+
273+
# Header 2
274+
275+
{% include-markdown "{filepath}" %}
276+
''',
277+
[],
278+
id='include-markdown-recursive=false',
279+
),
254280
),
255281
)
256282
def test_nested_include(

0 commit comments

Comments
 (0)