Skip to content

Commit

Permalink
Add tests for inclusions using URLs
Browse files Browse the repository at this point in the history
  • Loading branch information
mondeja committed Jul 31, 2023
1 parent 5326692 commit 1de4917
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 2 deletions.
2 changes: 0 additions & 2 deletions src/mkdocs_include_markdown_plugin/event.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,6 @@ def found_include_tag(match: re.Match[str]) -> str:
)
if is_url(filename):
file_paths_to_include = [file_path_glob]
logger.info('url found: ' + file_path_glob)

if not file_paths_to_include:
lineno = lineno_from_content_start(
Expand Down Expand Up @@ -476,7 +475,6 @@ def found_include_markdown_tag(match: re.Match[str]) -> str:

if is_url(filename):
file_paths_to_include = [file_path_glob]
logger.info('url found: ' + file_path_glob)

if not file_paths_to_include:
lineno = lineno_from_content_start(
Expand Down
21 changes: 21 additions & 0 deletions tests/test_unit/test_include.py
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,26 @@
id='dedent=true',
),
# Include from URL
pytest.param(
'''# Header
{% include "https://raw.githubusercontent.com/mondeja/mkdocs-include-markdown-plugin/master/examples/basic/docs/included.md" %}
''', # noqa: E501
'(not used)\n',
'''# Header
Some ignored content.
<--start-->
Some included content.
''',
[],
id='url',
),
# Content unindentation + preserve includer indent
pytest.param(
'''# Header
Expand Down Expand Up @@ -336,6 +356,7 @@
[],
id='rstrip-windows-trailing-newlines',
),
),
)
def test_include(
Expand Down
28 changes: 28 additions & 0 deletions tests/test_unit/test_include_markdown.py
Original file line number Diff line number Diff line change
Expand Up @@ -590,6 +590,34 @@
id='heading-offset=-90',
),
# Include from URL
pytest.param(
'''# Header
{%
include-markdown "https://raw.githubusercontent.com/mondeja/mkdocs-include-markdown-plugin/master/examples/basic/docs/included.md"
%}
After include.
''', # noqa: E501
'foo (not used)\n',
'''# Header
<!-- BEGIN INCLUDE https://raw.githubusercontent.com/mondeja/mkdocs-include-markdown-plugin/master/examples/basic/docs/included.md -->
Some ignored content.
<--start-->
Some included content.
<!-- END INCLUDE -->
After include.
''', # noqa: E501
[],
id='url',
),
# Custom encoding
pytest.param(
'''# Header
Expand Down

0 comments on commit 1de4917

Please sign in to comment.