mirror of
https://github.com/Hopiu/djLint.git
synced 2026-03-16 21:40:24 +00:00
fix(cssbeautify): added support for ignore in cssbeautifier
This commit is contained in:
parent
a1c7376a8c
commit
8a3c60c72b
3 changed files with 46 additions and 9 deletions
|
|
@ -20,13 +20,37 @@ def format_css(html: str, config: Config) -> str:
|
|||
inner_indent = indent + config.indent
|
||||
opts = BeautifierOptions(config.css_config)
|
||||
|
||||
beautified = (
|
||||
"\n"
|
||||
+ inner_indent
|
||||
+ ("\n" + inner_indent).join(
|
||||
cssbeautifier.beautify(match.group(3), opts).splitlines()
|
||||
)
|
||||
)
|
||||
beautified_lines = cssbeautifier.beautify(match.group(3), opts).splitlines()
|
||||
beautified = ""
|
||||
|
||||
# add indent back
|
||||
ignore_indent = False
|
||||
for line in beautified_lines:
|
||||
|
||||
if re.search(
|
||||
re.compile(
|
||||
r"\/\*[ ]*?beautify[ ]+?ignore:end[ ]*?\*\/",
|
||||
re.DOTALL | re.IGNORECASE | re.MULTILINE,
|
||||
),
|
||||
line,
|
||||
):
|
||||
line = line.lstrip()
|
||||
ignore_indent = False
|
||||
|
||||
if ignore_indent is False:
|
||||
|
||||
beautified += "\n" + inner_indent + line
|
||||
else:
|
||||
beautified += "\n" + line
|
||||
|
||||
if re.search(
|
||||
re.compile(
|
||||
r"\/\*[ ]*?beautify[ ]+?ignore:start[ ]*?\*\/",
|
||||
re.DOTALL | re.IGNORECASE | re.MULTILINE,
|
||||
),
|
||||
line,
|
||||
):
|
||||
ignore_indent = True
|
||||
|
||||
return match.group(1) + match.group(2) + beautified + "\n" + indent
|
||||
|
||||
|
|
|
|||
|
|
@ -30,7 +30,7 @@ def format_js(html: str, config: Config) -> str:
|
|||
|
||||
if re.search(
|
||||
re.compile(
|
||||
r"\/\*[ ]*?beautify[ ]+?preserve:end[ ]*?\*\/",
|
||||
r"\/\*[ ]*?beautify[ ]+?(?:preserve|ignore):end[ ]*?\*\/",
|
||||
re.DOTALL | re.IGNORECASE | re.MULTILINE,
|
||||
),
|
||||
line,
|
||||
|
|
@ -46,7 +46,7 @@ def format_js(html: str, config: Config) -> str:
|
|||
|
||||
if re.search(
|
||||
re.compile(
|
||||
r"\/\*[ ]*?beautify[ ]+?preserve:start[ ]*?\*\/",
|
||||
r"\/\*[ ]*?beautify[ ]+?(?:preserve|ignore):start[ ]*?\*\/",
|
||||
re.DOTALL | re.IGNORECASE | re.MULTILINE,
|
||||
),
|
||||
line,
|
||||
|
|
|
|||
|
|
@ -6,3 +6,16 @@ function(){}
|
|||
|
||||
/* beautify preserve:end */
|
||||
</script>
|
||||
<script>
|
||||
/* beautify ignore:start */
|
||||
function(){}
|
||||
function(){}
|
||||
function(){}
|
||||
|
||||
/* beautify ignore:end */
|
||||
</script>
|
||||
<style>
|
||||
/* beautify ignore:start */
|
||||
.class {display: none;}
|
||||
/* beautify ignore:end */
|
||||
</style>
|
||||
|
|
|
|||
Loading…
Reference in a new issue