mirror of
https://github.com/Hopiu/djLint.git
synced 2026-04-22 14:04:47 +00:00
fix(formatter): fixed greedy regex issue when finding script and style tags
This commit is contained in:
parent
99b5ee2c1f
commit
ca7ff3a1c7
4 changed files with 17 additions and 2 deletions
|
|
@ -4,12 +4,15 @@ black==22.1.0; python_full_version >= "3.6.2"
|
||||||
click==8.0.3; python_version >= "3.6"
|
click==8.0.3; python_version >= "3.6"
|
||||||
colorama==0.4.4; (python_version >= "2.7" and python_full_version < "3.0.0") or (python_full_version >= "3.5.0")
|
colorama==0.4.4; (python_version >= "2.7" and python_full_version < "3.0.0") or (python_full_version >= "3.5.0")
|
||||||
coverage==6.4.2; python_version >= "3.7"
|
coverage==6.4.2; python_version >= "3.7"
|
||||||
|
cssbeautifier==1.14.4
|
||||||
|
editorconfig==0.12.3
|
||||||
execnet==1.9.0; python_version >= "3.6" and python_full_version < "3.0.0" or python_full_version >= "3.5.0" and python_version >= "3.6"
|
execnet==1.9.0; python_version >= "3.6" and python_full_version < "3.0.0" or python_full_version >= "3.5.0" and python_version >= "3.6"
|
||||||
html-tag-names==0.1.2; python_version >= "3.7" and python_version < "4.0"
|
html-tag-names==0.1.2; python_version >= "3.7" and python_version < "4.0"
|
||||||
html-void-elements==0.1.0; python_version >= "3.7" and python_version < "4.0"
|
html-void-elements==0.1.0; python_version >= "3.7" and python_version < "4.0"
|
||||||
importlib-metadata==4.11.0; python_version >= "3.7"
|
importlib-metadata==4.11.0; python_version >= "3.7"
|
||||||
iniconfig==1.1.1; python_version >= "3.7"
|
iniconfig==1.1.1; python_version >= "3.7"
|
||||||
isort==5.10.1; python_full_version >= "3.6.1" and python_version < "4.0"
|
isort==5.10.1; python_full_version >= "3.6.1" and python_version < "4.0"
|
||||||
|
jsbeautifier==1.14.4
|
||||||
mypy-extensions==0.4.3; python_full_version >= "3.6.2"
|
mypy-extensions==0.4.3; python_full_version >= "3.6.2"
|
||||||
packaging==21.3; python_version >= "3.7"
|
packaging==21.3; python_version >= "3.7"
|
||||||
pathspec==0.9.0; (python_version >= "2.7" and python_full_version < "3.0.0") or (python_full_version >= "3.5.0")
|
pathspec==0.9.0; (python_version >= "2.7" and python_full_version < "3.0.0") or (python_full_version >= "3.5.0")
|
||||||
|
|
@ -23,6 +26,7 @@ pytest-xdist==2.5.0; python_version >= "3.6"
|
||||||
pytest==7.1.2; python_version >= "3.7"
|
pytest==7.1.2; python_version >= "3.7"
|
||||||
pyyaml==6.0; python_version >= "3.6"
|
pyyaml==6.0; python_version >= "3.6"
|
||||||
regex==2022.1.18
|
regex==2022.1.18
|
||||||
|
six==1.16.0; python_version >= "2.7" and python_full_version < "3.0.0" or python_full_version >= "3.3.0"
|
||||||
tomli==2.0.1; python_full_version <= "3.11.0a6" and python_version >= "3.7" and python_full_version >= "3.6.2" or python_version < "3.11"
|
tomli==2.0.1; python_full_version <= "3.11.0a6" and python_version >= "3.7" and python_full_version >= "3.6.2" or python_version < "3.11"
|
||||||
tqdm==4.62.3; (python_version >= "2.7" and python_full_version < "3.0.0") or (python_full_version >= "3.4.0")
|
tqdm==4.62.3; (python_version >= "2.7" and python_full_version < "3.0.0") or (python_full_version >= "3.4.0")
|
||||||
typed-ast==1.4.3; python_version < "3.8" and implementation_name == "cpython" and python_full_version >= "3.6.2"
|
typed-ast==1.4.3; python_version < "3.8" and implementation_name == "cpython" and python_full_version >= "3.6.2"
|
||||||
|
|
|
||||||
|
|
@ -13,9 +13,13 @@ def format_css(html: str, config: Config) -> str:
|
||||||
|
|
||||||
def launch_formatter(config: Config, match: re.Match) -> str:
|
def launch_formatter(config: Config, match: re.Match) -> str:
|
||||||
"""Add break after if not in ignored block."""
|
"""Add break after if not in ignored block."""
|
||||||
|
if not match.group(3).strip():
|
||||||
|
return match.group()
|
||||||
|
|
||||||
indent = len(match.group(1)) * " "
|
indent = len(match.group(1)) * " "
|
||||||
inner_indent = indent + config.indent
|
inner_indent = indent + config.indent
|
||||||
opts = BeautifierOptions(config.css_config)
|
opts = BeautifierOptions(config.css_config)
|
||||||
|
|
||||||
beautified = (
|
beautified = (
|
||||||
"\n"
|
"\n"
|
||||||
+ inner_indent
|
+ inner_indent
|
||||||
|
|
@ -30,7 +34,7 @@ def format_css(html: str, config: Config) -> str:
|
||||||
|
|
||||||
return re.sub(
|
return re.sub(
|
||||||
re.compile(
|
re.compile(
|
||||||
r"([ ]*?)(<style\b.*?>)(.+?)(?=</style>)",
|
r"([ ]*?)(<(?:style)\b(?:\"[^\"]*\"|'[^']*'|{[^}]*}|[^'\">{}])*>)(.*?)(?=</style>)",
|
||||||
re.IGNORECASE | re.DOTALL,
|
re.IGNORECASE | re.DOTALL,
|
||||||
),
|
),
|
||||||
func,
|
func,
|
||||||
|
|
|
||||||
|
|
@ -13,6 +13,9 @@ def format_js(html: str, config: Config) -> str:
|
||||||
|
|
||||||
def launch_formatter(config: Config, match: re.Match) -> str:
|
def launch_formatter(config: Config, match: re.Match) -> str:
|
||||||
"""Add break after if not in ignored block."""
|
"""Add break after if not in ignored block."""
|
||||||
|
if not match.group(3).strip():
|
||||||
|
return match.group()
|
||||||
|
|
||||||
indent = len(match.group(1)) * " "
|
indent = len(match.group(1)) * " "
|
||||||
inner_indent = indent + config.indent
|
inner_indent = indent + config.indent
|
||||||
opts = BeautifierOptions(config.js_config)
|
opts = BeautifierOptions(config.js_config)
|
||||||
|
|
@ -31,7 +34,7 @@ def format_js(html: str, config: Config) -> str:
|
||||||
|
|
||||||
return re.sub(
|
return re.sub(
|
||||||
re.compile(
|
re.compile(
|
||||||
r"([ ]*?)(<script\b.*?>)(.+?)(?=</script>)",
|
r"([ ]*?)(<(?:script)\b(?:\"[^\"]*\"|'[^']*'|{[^}]*}|[^'\">{}])*>)(.*?)(?=</script>)",
|
||||||
re.IGNORECASE | re.DOTALL,
|
re.IGNORECASE | re.DOTALL,
|
||||||
),
|
),
|
||||||
func,
|
func,
|
||||||
|
|
|
||||||
|
|
@ -15,3 +15,7 @@
|
||||||
width: 12px
|
width: 12px
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
|
<script src="{% static '/js/shared.min.js' %}"></script>
|
||||||
|
<script src="{% static '/js/alive.min.js' %}"></script>
|
||||||
|
<script src="{% static '/js/search.min.js' %}" defer async></script>
|
||||||
|
<script src="{% static '/js/utility.min.js' %}" defer async></script>
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue