mirror of
https://github.com/Hopiu/djLint.git
synced 2026-03-17 05:50:24 +00:00
fix(image tag): added image tag to template break tag list. srcset formatting
closes #444
This commit is contained in:
parent
fceff25433
commit
0d170aab6c
3 changed files with 37 additions and 6 deletions
|
|
@ -145,18 +145,24 @@ def format_attributes(config: Config, html: str, match: re.match) -> str:
|
|||
# for the equals sign
|
||||
quote_length += 1
|
||||
|
||||
if config.format_attribute_template_tags:
|
||||
join_space = "\n" + spacing
|
||||
else:
|
||||
join_space = (
|
||||
"\n" + spacing + int(quote_length + len(attrib_name or "")) * " "
|
||||
)
|
||||
|
||||
# format style attribute
|
||||
if attrib_name and attrib_name.lower() == "style":
|
||||
if config.format_attribute_template_tags:
|
||||
join_space = "\n" + spacing
|
||||
else:
|
||||
join_space = (
|
||||
"\n" + spacing + int(quote_length + len(attrib_name or "")) * " "
|
||||
)
|
||||
attrib_value = (";" + join_space).join(
|
||||
[value.strip() for value in attrib_value.split(";") if value.strip()]
|
||||
)
|
||||
|
||||
elif attrib_name and attrib_name.lower() in ["srcset", "data-srcset", "sizes"]:
|
||||
attrib_value = ("," + join_space).join(
|
||||
[value.strip() for value in attrib_value.split(",") if value.strip()]
|
||||
)
|
||||
|
||||
# format template stuff
|
||||
if config.format_attribute_template_tags:
|
||||
if attrib_value and attrib_name not in config.ignored_attributes:
|
||||
|
|
|
|||
|
|
@ -614,6 +614,7 @@ class Config:
|
|||
| endraw
|
||||
| call
|
||||
| endcall
|
||||
| image
|
||||
"""
|
||||
+ self.custom_blocks
|
||||
+ r"""
|
||||
|
|
|
|||
|
|
@ -29,6 +29,30 @@ from click.testing import CliRunner
|
|||
from tests.conftest import reformat
|
||||
|
||||
|
||||
def test_srcset(runner: CliRunner, tmp_file: TextIO) -> None:
|
||||
output = reformat(
|
||||
tmp_file,
|
||||
runner,
|
||||
b"""<img {% image value.image fill-640x360 as block_image_640 %}
|
||||
{% image value.image fill-768x432 as block_image_768 %}
|
||||
{% image value.image fill-1024x576 as block_image_1024 %}
|
||||
{% image value.image fill-1600x900 as block_image_1600 %}
|
||||
data-src="{{ block_image_640.url }}"
|
||||
data-srcset="{{ block_image_640.url }} 640w,
|
||||
{{ block_image_768.url }} 768w,
|
||||
{{ block_image_1024.url }} 1024w,
|
||||
{{ block_image_1600.url }} 1600w"
|
||||
sizes="(min-width: 1200px) 458px,
|
||||
(min-width: 992px) 374px,
|
||||
(min-width: 768px) 720px,
|
||||
calc(100vw - 30px)"
|
||||
class="richtext-image imageblock overflow {{ value.image_position }} lazy"
|
||||
title="{{ value.image.title }}"
|
||||
alt="Block image"/>""",
|
||||
)
|
||||
assert output.exit_code == 0
|
||||
|
||||
|
||||
def test_long_attributes(runner: CliRunner, tmp_file: TextIO) -> None:
|
||||
output = reformat(
|
||||
tmp_file,
|
||||
|
|
|
|||
Loading…
Reference in a new issue