Skip to content

Commit

Permalink
fixed #34
Browse files Browse the repository at this point in the history
  • Loading branch information
christopherpickering committed Oct 1, 2021
1 parent 2e094e6 commit 722fe18
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 20 deletions.
2 changes: 1 addition & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
project = "djlint"
copyright = "2021, Riverside Healthcare"
author = "Christopher Pickering"
release = "0.4.7"
release = "0.4.8"
version = release

# -- General configuration ---------------------------------------------------
Expand Down
6 changes: 5 additions & 1 deletion docs/djlint/changelog.rst
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
Changelog
=========

0.4.8
-----
- Fixed bug `#34 <https://github.com/Riverside-Healthcare/djLint/issues/34>`_

0.4.7
-----
- Moved ``source`` tag to single line tags

0.4.6
-----
- fix bug `#31 <https://github.com/Riverside-Healthcare/djLint/issues/31>`_
- Fixed bug `#31 <https://github.com/Riverside-Healthcare/djLint/issues/31>`_

0.4.5
-----
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ build-backend = "poetry.core.masonry.api"

[tool.poetry]
name="djlint"
version="0.4.7"
version="0.4.8"
description="HTML Template Linter and Formatter"
license="GPL-3.0-or-later"
authors=["Christopher Pickering <cpickering@rhc.net>"]
Expand Down
15 changes: 6 additions & 9 deletions src/djlint/formatter/expand_html.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,12 @@ def _flatten_attributes(match: re.Match) -> str:
def _should_ignore(config: Config, html: str, match: re.Match) -> bool:
"""Do not add whitespace if the tag is in a non indent block."""
return any(
any(
ignored_match.start() < match.start(1)
and ignored_match.end() > match.end(1)
for ignored_match in re.finditer(
block % re.escape(match.group(1)),
html,
re.DOTALL | re.IGNORECASE | re.VERBOSE,
)
ignored_match.start() < match.start(1) and ignored_match.end() > match.end(1)
for ignored_match in re.finditer(
config.ignored_blocks,
html,
re.DOTALL | re.IGNORECASE | re.VERBOSE,
)
for block in config.ignored_blocks
)


Expand Down Expand Up @@ -78,6 +74,7 @@ def add_html_line(out_format: str, match: re.Match) -> str:
add_left,
html,
)

# <tag>
html = re.sub(
re.compile(fr"(<(?:{html_tags})>)(?=[^\n])", flags=re.IGNORECASE | re.VERBOSE),
Expand Down
14 changes: 7 additions & 7 deletions src/djlint/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -400,13 +400,13 @@ def __init__(
"""
)

self.ignored_blocks: list = [
r"<(script|style|pre|textarea).*?(?:%s).*?</(\1)>",
r"<!--.*?(?:%s).*?-->",
r"{\*.*?(?:%s).*?\*}",
r"{\#.*?(?:%s).*?\#}",
r"<\?php.*?(?:%s).*?\?>",
]
self.ignored_blocks: str = r"""
<(script|style|pre|textarea).*?</(\1)>
| <!--.*?-->
| {\*.*?\*}
| {\#.*?\#}
| <\?php.*?\?>
"""

self.ignored_inline_blocks: str = r"""
<!--.*?-->
Expand Down
27 changes: 26 additions & 1 deletion tests/test_html.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
pytest tests/test_html.py --cov=src/djlint --cov-branch \
--cov-report xml:coverage.xml --cov-report term-missing
pytest tests/test_html.py::test_ignored_attributes --cov=src/djlint --cov-branch \
pytest tests/test_html.py::test_ignored_block --cov=src/djlint --cov-branch \
--cov-report xml:coverage.xml --cov-report term-missing
Expand Down Expand Up @@ -217,3 +217,28 @@ def test_picture_source_img_tags(runner: CliRunner, tmp_file: TextIO) -> None:
</picture>
"""
)


def test_ignored_block(runner: CliRunner, tmp_file: TextIO) -> None:
output = reformat(
tmp_file,
runner,
b"""<!-- <span> -->
<div><p><span></span></p></div>
<!-- <div> -->
""",
)

assert output["exit_code"] == 1

assert (
output["text"]
== """<!-- <span> -->
<div>
<p>
<span></span>
</p>
</div>
<!-- <div> -->
"""
)

0 comments on commit 722fe18

Please sign in to comment.