|
55 | 55 | @dataclass |
56 | 56 | class Settings: # noqa: D101 |
57 | 57 | exclude: list[str] | None |
| 58 | + include_from_url: bool = False |
58 | 59 |
|
59 | 60 |
|
60 | 61 | def get_file_content( # noqa: PLR0913, PLR0915 |
@@ -169,14 +170,25 @@ def found_include_tag( # noqa: PLR0912, PLR0915 |
169 | 170 | order, |
170 | 171 | ) |
171 | 172 |
|
172 | | - if is_url and 'order' in used_arguments: # pragma: no cover |
173 | | - location = process.file_lineno_message( |
174 | | - page_src_path, docs_dir, directive_lineno(), |
175 | | - ) |
176 | | - logger.warning( |
177 | | - f"Ignoring 'order' argument of 'include' directive" |
178 | | - f" at {location} because the included path is a URL", |
179 | | - ) |
| 173 | + if is_url: |
| 174 | + if 'order' in used_arguments: # pragma: no cover |
| 175 | + location = process.file_lineno_message( |
| 176 | + page_src_path, docs_dir, directive_lineno(), |
| 177 | + ) |
| 178 | + logger.warning( |
| 179 | + f"Ignoring 'order' argument of 'include' directive" |
| 180 | + f" at {location} because the included path is a URL", |
| 181 | + ) |
| 182 | + |
| 183 | + if not settings.include_from_url: |
| 184 | + location = process.file_lineno_message( |
| 185 | + page_src_path, docs_dir, directive_lineno(), |
| 186 | + ) |
| 187 | + raise PluginError( |
| 188 | + f'Including from URL at {location} is not allowed because' |
| 189 | + ' include-markdown is configured with include_from_url set' |
| 190 | + ' to false', |
| 191 | + ) |
180 | 192 |
|
181 | 193 | if not file_paths_to_include: |
182 | 194 | location = process.file_lineno_message( |
@@ -414,14 +426,25 @@ def found_include_markdown_tag( # noqa: PLR0912, PLR0915 |
414 | 426 | order, |
415 | 427 | ) |
416 | 428 |
|
417 | | - if is_url and 'order' in used_arguments: # pragma: no cover |
418 | | - location = process.file_lineno_message( |
419 | | - page_src_path, docs_dir, directive_lineno(), |
420 | | - ) |
421 | | - logger.warning( |
422 | | - f"Ignoring 'order' argument of 'include-markdown' directive" |
423 | | - f" at {location} because the included path is a URL", |
424 | | - ) |
| 429 | + if is_url: |
| 430 | + if 'order' in used_arguments: # pragma: no cover |
| 431 | + location = process.file_lineno_message( |
| 432 | + page_src_path, docs_dir, directive_lineno(), |
| 433 | + ) |
| 434 | + logger.warning( |
| 435 | + f"Ignoring 'order' argument of 'include-markdown' directive" |
| 436 | + f" at {location} because the included path is a URL", |
| 437 | + ) |
| 438 | + |
| 439 | + if not settings.include_from_url: |
| 440 | + location = process.file_lineno_message( |
| 441 | + page_src_path, docs_dir, directive_lineno(), |
| 442 | + ) |
| 443 | + raise PluginError( |
| 444 | + f'Including from URL at {location} is not allowed because' |
| 445 | + ' include-markdown is configured with include_from_url set' |
| 446 | + ' to false', |
| 447 | + ) |
425 | 448 |
|
426 | 449 | if not file_paths_to_include: |
427 | 450 | location = process.file_lineno_message( |
@@ -713,6 +736,7 @@ def on_page_markdown( |
713 | 736 | }, |
714 | 737 | Settings( |
715 | 738 | exclude=config.exclude, |
| 739 | + include_from_url=config.include_from_url, |
716 | 740 | ), |
717 | 741 | files_watcher=plugin._files_watcher, |
718 | 742 | http_cache=plugin._cache or http_cache, |
|
0 commit comments