mirror of
https://github.com/Hopiu/djLint.git
synced 2026-05-01 10:24:45 +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
|
inner_indent = indent + config.indent
|
||||||
opts = BeautifierOptions(config.css_config)
|
opts = BeautifierOptions(config.css_config)
|
||||||
|
|
||||||
beautified = (
|
beautified_lines = cssbeautifier.beautify(match.group(3), opts).splitlines()
|
||||||
"\n"
|
beautified = ""
|
||||||
+ inner_indent
|
|
||||||
+ ("\n" + inner_indent).join(
|
# add indent back
|
||||||
cssbeautifier.beautify(match.group(3), opts).splitlines()
|
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
|
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(
|
if re.search(
|
||||||
re.compile(
|
re.compile(
|
||||||
r"\/\*[ ]*?beautify[ ]+?preserve:end[ ]*?\*\/",
|
r"\/\*[ ]*?beautify[ ]+?(?:preserve|ignore):end[ ]*?\*\/",
|
||||||
re.DOTALL | re.IGNORECASE | re.MULTILINE,
|
re.DOTALL | re.IGNORECASE | re.MULTILINE,
|
||||||
),
|
),
|
||||||
line,
|
line,
|
||||||
|
|
@ -46,7 +46,7 @@ def format_js(html: str, config: Config) -> str:
|
||||||
|
|
||||||
if re.search(
|
if re.search(
|
||||||
re.compile(
|
re.compile(
|
||||||
r"\/\*[ ]*?beautify[ ]+?preserve:start[ ]*?\*\/",
|
r"\/\*[ ]*?beautify[ ]+?(?:preserve|ignore):start[ ]*?\*\/",
|
||||||
re.DOTALL | re.IGNORECASE | re.MULTILINE,
|
re.DOTALL | re.IGNORECASE | re.MULTILINE,
|
||||||
),
|
),
|
||||||
line,
|
line,
|
||||||
|
|
|
||||||
|
|
@ -6,3 +6,16 @@ function(){}
|
||||||
|
|
||||||
/* beautify preserve:end */
|
/* beautify preserve:end */
|
||||||
</script>
|
</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