Skip to content

Commit

Permalink
Revert to single quotes in multiline strings
Browse files Browse the repository at this point in the history
  • Loading branch information
mondeja committed Oct 12, 2023
1 parent b03bfae commit e6abfbb
Show file tree
Hide file tree
Showing 13 changed files with 476 additions and 475 deletions.
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ convention = "google"

[tool.ruff.flake8-quotes]
inline-quotes = "single"
multiline-quotes = "single"

[tool.ruff.flake8-pytest-style]
fixture-parentheses = false
Expand Down
4 changes: 2 additions & 2 deletions src/mkdocs_include_markdown_plugin/directive.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class DirectiveBoolArgument(TypedDict): # noqa: D101
# In the following regular expression, the substrings "$OPENING_TAG"
# and "$CLOSING_TAG" will be replaced by the effective opening and
# closing tags in the `on_config` plugin event.
INCLUDE_TAG_RE = rf"""
INCLUDE_TAG_RE = rf'''
(?P<_includer_indent>[ \t\f\v\w{re.escape(string.punctuation)}]*?)$OPENING_TAG
\s*
include
Expand All @@ -54,7 +54,7 @@ class DirectiveBoolArgument(TypedDict): # noqa: D101
(?P<arguments>.*?)
\s*
$CLOSING_TAG
""" # noqa: E501
''' # noqa: E501

TRUE_FALSE_STR_BOOL = {
'true': True,
Expand Down
12 changes: 6 additions & 6 deletions src/mkdocs_include_markdown_plugin/process.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
# Perl implementation but this doesn't seem possible in Python, the current
# implementation only reaches two levels.
MARKDOWN_LINK_REGEX = re.compile( # noqa: DUO138
r"""
r'''
( # wrap whole match in $1
(?<!!) # don't match images - negative lookbehind
\[
Expand All @@ -59,14 +59,14 @@
)? # title is optional
\)
)
""",
''',
flags=re.VERBOSE,
)

# Matches markdown inline images.
# e.g. ![alt-text](path/to/image.png)
MARKDOWN_IMAGE_REGEX = re.compile(
r"""
r'''
( # wrap whole match in $1
!\[
(.*?) # alt text = $2
Expand All @@ -83,14 +83,14 @@
)? # title is optional
\)
)
""",
''',
flags=re.VERBOSE,
)

# Matches markdown link definitions.
# e.g. [scikit-learn]: https://github.com/scikit-learn/scikit-learn
MARKDOWN_LINK_DEFINITION_REGEX = re.compile(
r"""
r'''
^[ ]{0,4}\[(.+)\]: # id = $1
[ \t]*
\n? # maybe *one* newline
Expand All @@ -107,7 +107,7 @@
[ \t]*
)? # title is optional
(?:\n+|\Z)
""",
''',
flags=re.VERBOSE | re.MULTILINE,
)

Expand Down
12 changes: 6 additions & 6 deletions tests/test_integration/test_cache_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,19 @@
(
(
'https://raw.githubusercontent.com/mondeja/mkdocs-include-markdown-plugin/master/examples/basic/mkdocs.yml', # noqa: E501
"""site_name: Foo
'''site_name: Foo
plugins:
- include-markdown
""",
''',
),
(
'https://raw.githubusercontent.com/mondeja/mkdocs-include-markdown-plugin/master/examples/basic/docs/included.md', # noqa: E501
"""Some ignored content.
'''Some ignored content.
<--start-->
Some included content.
""",
''',
),
),
)
Expand Down Expand Up @@ -58,10 +58,10 @@ def test_page_included_by_url_is_cached(

def run():
return on_page_markdown(
f"""{{%
f'''{{%
{directive} "{url}"
comments=false
%}}""",
%}}''',
page(tmp_path / 'includer.md'),
tmp_path,
http_cache=cache,
Expand Down
60 changes: 30 additions & 30 deletions tests/test_unit/test_arguments.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,10 @@ def test_invalid_bool_arguments(directive, arguments, page, tmp_path, caplog):

with pytest.raises(PluginError) as exc:
on_page_markdown(
f"""{{%
f'''{{%
{directive} "{page_to_include_filepath}"
{argument_name}=invalidoption
%}}""",
%}}''',
page(tmp_path / filename),
tmp_path,
)
Expand All @@ -59,20 +59,20 @@ def test_invalid_bool_arguments(directive, arguments, page, tmp_path, caplog):
@parametrize_directives
def test_start_end_mixed_quotes(directive, page, caplog, tmp_path):
page_to_include_filepath = tmp_path / 'included.md'
page_to_include_filepath.write_text("""Content that should be ignored
page_to_include_filepath.write_text('''Content that should be ignored
<!-- "s'tar't" -->
Content to include
<!-- 'en"d' -->
More content that should be ignored
""")
''')

result = on_page_markdown(
f"""{{%
f'''{{%
{directive} "{page_to_include_filepath}"
comments=false
start='<!-- "s\\'tar\\'t" -->'
end="<!-- 'en\\"d' -->"
%}}""",
%}}''',
page(tmp_path / 'includer.md'),
tmp_path,
)
Expand All @@ -91,22 +91,22 @@ def test_invalid_start_end_arguments(
tmp_path,
):
page_to_include_filepath = tmp_path / 'included.md'
included_content = """Content that should be ignored
included_content = '''Content that should be ignored
<!-- start -->
Content to include
<!-- end -->
More content that should be ignored
"""
'''
page_to_include_filepath.write_text(included_content)

with pytest.raises(PluginError) as exc:
on_page_markdown(
f"""
f'''
{{%
{directive} "{page_to_include_filepath}"
comments=false
{argument}=''
%}}""",
%}}''',
page(tmp_path / 'includer.md'),
tmp_path,
)
Expand Down Expand Up @@ -135,11 +135,11 @@ def test_exclude_double_quote_escapes(directive, page, tmp_path):

includer_glob = os.path.join(str(drectory_to_include), '*.md')
result = on_page_markdown(
f"""{{%
f'''{{%
{directive} "{includer_glob}"
comments=false
exclude="{page_to_exclude_escaped_filepath}"
%}}""",
%}}''',
page(tmp_path / 'includer.md'),
tmp_path,
)
Expand All @@ -161,11 +161,11 @@ def test_invalid_exclude_argument(directive, page, tmp_path, caplog):
includer_glob = os.path.join(str(drectory_to_include), '*.md')
with pytest.raises(PluginError) as exc:
on_page_markdown(
f"""{{%
f'''{{%
{directive} "{includer_glob}"
comments=false
exclude=
%}}""",
%}}''',
page(tmp_path / 'includer.md'),
tmp_path,
)
Expand All @@ -184,11 +184,11 @@ def test_empty_encoding_argument(directive, page, tmp_path, caplog):

with pytest.raises(PluginError) as exc:
on_page_markdown(
f"""{{%
f'''{{%
{directive} "{page_to_include_filepath}"
comments=false
encoding=
%}}""",
%}}''',
page(tmp_path / 'includer.md'),
tmp_path,
)
Expand Down Expand Up @@ -231,11 +231,11 @@ def test_invalid_heading_offset_arguments(

with pytest.raises(PluginError) as exc:
on_page_markdown(
f"""{{%
f'''{{%
include-markdown "{page_to_include_filepath}"
comments=false
heading-offset={argument_value}
%}}""",
%}}''',
page(tmp_path / 'includer.md'),
tmp_path,
)
Expand Down Expand Up @@ -289,10 +289,10 @@ def test_escaped_double_quotes(
page_to_include_filepath,
).replace('"', '\\"')
result = on_page_markdown(
f"""{{%
f'''{{%
{directive} "{escaped_page_to_include_filepath}"
{'comments=false' if directive == 'include-markdown' else ''}
%}}""",
%}}''',
page(tmp_path / 'includer.md'),
tmp_path,
)
Expand All @@ -312,10 +312,10 @@ def test_escaped_single_quotes(
page_to_include_filepath,
).replace("'", "\\'")
result = on_page_markdown(
f"""{{%
f'''{{%
{directive} '{escaped_page_to_include_filepath}'
{'comments=false' if directive == 'include-markdown' else ''}
%}}""",
%}}''',
page(tmp_path / 'includer.md'),
tmp_path,
)
Expand All @@ -332,10 +332,10 @@ def test_unescaped_double_quotes(
page_to_include_filepath.write_text(included_content)

result = on_page_markdown(
f"""{{%
f'''{{%
{directive} '{page_to_include_filepath}'
{'comments=false' if directive == 'include-markdown' else ''}
%}}""",
%}}''',
page(tmp_path / 'includer.md'),
tmp_path,
)
Expand All @@ -351,10 +351,10 @@ def test_unescaped_single_quotes(
page_to_include_filepath.write_text(included_content)

result = on_page_markdown(
f"""{{%
f'''{{%
{directive} "{page_to_include_filepath}"
{'comments=false' if directive == 'include-markdown' else ''}
%}}""",
%}}''',
page(tmp_path / 'includer.md'),
tmp_path,
)
Expand Down Expand Up @@ -385,10 +385,10 @@ def test_mixed_quotes(
else:
escaped_page_to_include_filepath = page_to_include_filepath

markdown = f"""{{%
markdown = f'''{{%
{directive} {quote}{escaped_page_to_include_filepath}{quote}
{'comments=false' if directive == 'include-markdown' else ''}
%}}"""
%}}'''

func = functools.partial(
on_page_markdown,
Expand Down Expand Up @@ -427,11 +427,11 @@ def test_no_filename(self, directive, page, tmp_path, caplog):

@parametrize_directives
def test_non_existent_filename(self, directive, page, tmp_path, caplog):
page_content = f"""{{%
page_content = f'''{{%
{directive} "/path/to/file/that/does/not/exists"
start="<!--start-here-->"
end="<!--end-here-->"
%}}"""
%}}'''

page_filepath = tmp_path / 'example.md'
page_filepath.write_text(page_content)
Expand Down
24 changes: 12 additions & 12 deletions tests/test_unit/test_encoding.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,22 @@
@parametrize_directives
def test_encoding(directive, page, tmp_path):
page_to_include_file = tmp_path / 'included.md'
page_to_include_file.write_text("""Á
page_to_include_file.write_text('''Á
<!-- start -->
Content to include
<!-- end -->
É
""")
''')

with pytest.raises(UnicodeDecodeError):
on_page_markdown(
f"""{{%
f'''{{%
{directive} "{page_to_include_file}"
comments=false
start='<!-- start -->'
end="<!-- end -->"
encoding="ascii"
%}}""",
%}}''',
page(tmp_path / 'includer.md'),
tmp_path,
)
Expand All @@ -31,20 +31,20 @@ def test_encoding(directive, page, tmp_path):
@parametrize_directives
def test_default_encoding(directive, page, tmp_path):
page_to_include_file = tmp_path / 'included.md'
page_to_include_file.write_text("""Á
page_to_include_file.write_text('''Á
<!-- start -->
Content to include
<!-- end -->
É
""")
''')

result = on_page_markdown(
f"""{{%
f'''{{%
{directive} "{page_to_include_file}"
comments=false
start="<!-- start -->"
end="<!-- end -->"
%}}""",
%}}''',
page(tmp_path / 'includer.md'),
tmp_path,
)
Expand All @@ -55,21 +55,21 @@ def test_default_encoding(directive, page, tmp_path):
@parametrize_directives
def test_explicit_default_encoding(directive, page, tmp_path):
page_to_include_file = tmp_path / 'included.md'
page_to_include_file.write_text("""Á
page_to_include_file.write_text('''Á
<!-- start -->
Content to include
<!-- end -->
É
""")
''')

result = on_page_markdown(
f"""{{%
f'''{{%
{directive} "{page_to_include_file}"
comments=false
start='<!-- start -->'
end="<!-- end -->"
encoding="utf-8"
%}}""",
%}}''',
page(tmp_path / 'includer.md'),
tmp_path,
)
Expand Down

0 comments on commit e6abfbb

Please sign in to comment.