Skip to content

Commit 432bac4

Browse files
committed
added support for string type src in image
1 parent f34ed35 commit 432bac4

File tree

5 files changed

+24
-3
lines changed

5 files changed

+24
-3
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<figure><picture><source srcset="https://placekitten.com/200/301" type="image"/><source srcset="https://placekitten.com/200/301" type="image"/><img src="https://placekitten.com/200/301" alt="Sleepy Kitten" width="300" height="400"/></picture><figcaption>Cute Kitty</figcaption></figure>
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"type": "doc",
3+
"content": [
4+
{
5+
"type": "image",
6+
"attrs": {
7+
"src": "https://placekitten.com/200/301",
8+
"alt": "Sleepy Kitten",
9+
"caption": "Cute Kitty",
10+
"height": 400,
11+
"width": 300
12+
}
13+
}
14+
]
15+
}

tests/test_transform.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
"image-no_caption",
2222
"image-mime_type",
2323
"image-height_width",
24+
"image-src_string",
2425
"featuredimage",
2526
"featuredimage-is_renderable",
2627
"featuredimage-missing_caption",

tiptapy/macros.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,11 @@ def make_img_src(attrs):
2020
alt = attrs.get("alt", "").strip()
2121
height = attrs.get("height", "")
2222
width = attrs.get("width", "")
23-
fallback_url = attrs["src"]["fallback"].strip()
23+
if isinstance(attrs["src"], dict):
24+
fallback_url = attrs["src"]["fallback"].strip()
25+
else:
26+
fallback_url = attrs["src"].strip()
27+
2428
img = f'img src="{fallback_url}"'
2529
if alt:
2630
img += f' alt="{alt}"'

tiptapy/templates/image.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
{%- set alt = node.attrs.alt|trim -%}
44
{%- set height = node.attrs.height -%}
55
{%- set width = node.attrs.width -%}
6-
{%- set image_url = node.attrs.src.image|trim -%}
6+
{%- set image_url = (node.attrs.src.image if node.attrs.src is mapping else node.attrs.src)|trim -%}
77
{%- set image_type = url2mime(image_url) -%}
8-
{%- set fallback_url = node.attrs.src.fallback|trim -%}
8+
{%- set fallback_url = (node.attrs.src.fallback if node.attrs.src is mapping else node.attrs.src)|trim -%}
99
{%- set fallback_type = url2mime(fallback_url) -%}
1010

1111
{%- if image_url or fallback_url -%}

0 commit comments

Comments
 (0)