Skip to content

Commit

Permalink
attrs rendering added to more block types
Browse files Browse the repository at this point in the history
  • Loading branch information
Rajat Singla committed Jun 6, 2024
1 parent fbe3d69 commit 263fc07
Show file tree
Hide file tree
Showing 28 changed files with 67 additions and 54 deletions.
2 changes: 1 addition & 1 deletion tests/data/html/audio.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<figure class="audio-player-container"><div><audio src=https://getfoobar/audio/sohtdbcmxu-1581683086.mp3></audio><div class="audio-player audio-player-initialising">
<figure class="audio-player-container" id="b-NzgT2MAhuSTnpFyo-E3"><div><audio src=https://getfoobar/audio/sohtdbcmxu-1581683086.mp3></audio><div class="audio-player audio-player-initialising">
<div class="player-button">
<i class="icon audio-play-icon"></i>
</div>
Expand Down
2 changes: 1 addition & 1 deletion tests/data/html/code_block.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<div><pre><code data-lang="python"># Python Program to find the L.C.M. of two input number
<div id="b-NzgT2MAhuSTnpFyo-E4"><pre><code data-lang="python"># Python Program to find the L.C.M. of two input number

def compute_lcm(x, y):

Expand Down
2 changes: 1 addition & 1 deletion tests/data/html/data_attributes.html
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<div data-show-gap="true" data-type="imageStrip"><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><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="Happy Kitten" width="300" height="400"/></picture><figcaption>New Kitty</figcaption></figure></div>
<div data-show-gap="true" data-type="imageStrip"><figure id="b-NzgT2MAhuSTnpFyo-E5"><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><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="Happy Kitten" width="300" height="400"/></picture><figcaption>New Kitty</figcaption></figure></div>
2 changes: 1 addition & 1 deletion tests/data/html/document-pdf.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<figure class="file-attachment"><div class="file-attachment-panel">
<figure class="file-attachment" id="b-NzgT2MAhuSTnpFyo-E6"><div class="file-attachment-panel">
<div class="file-attachment-container">
<div class="file-type-container">
<span class="file-type"> pdf </span>
Expand Down
2 changes: 1 addition & 1 deletion tests/data/html/embed.html
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<div class="embed-wrapper youtube-wrapper"><figure><iframe width="480" height="270" src="https://www.youtube.com/embed/GJQsT-h0FTU?feature=oembed" frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe><figcaption>Extraction</figcaption></figure></div>
<div class="embed-wrapper youtube-wrapper" id="b-NzgT2MAhuSTnpFyo-E7"><figure><iframe width="480" height="270" src="https://www.youtube.com/embed/GJQsT-h0FTU?feature=oembed" frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe><figcaption>Extraction</figcaption></figure></div>
2 changes: 1 addition & 1 deletion tests/data/html/heading.html
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<h2><strong>This</strong> is a <br><em>word</em></h2>
<h2 id="b-NzgT2MAhuSTnpFyo-E8"><strong>This</strong> is a <br><em>word</em></h2>
2 changes: 1 addition & 1 deletion tests/data/html/horizontal_rule.html
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<hr>
<hr id="b-NzgT2MAhuSTnpFyo-E8"><hr>
2 changes: 1 addition & 1 deletion tests/data/html/image.html
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<figure><picture><source srcset="https://placekitten.com/200/301?text=&quot;escape me&quot;" type="image"/><source srcset="https://placekitten.com/198/654" type="image"/><img src="https://placekitten.com/198/654" alt="Sleepy Kitten"/></picture><figcaption>&lt;script&gt;alert(23)&lt;/script&gt;Cute Kitty</figcaption></figure>
<figure id="b-NzgT2MAhuSTnpFyo-E9"><picture><source srcset="https://placekitten.com/200/301?text=&quot;escape me&quot;" type="image"/><source srcset="https://placekitten.com/198/654" type="image"/><img src="https://placekitten.com/198/654" alt="Sleepy Kitten"/></picture><figcaption>&lt;script&gt;alert(23)&lt;/script&gt;Cute Kitty</figcaption></figure>
2 changes: 1 addition & 1 deletion tests/data/html/paragraph.html
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<p><sup>Quick brown fox jumps over the lazy dog. </sup></p><p id="ayZCtf1xgGPZnCVimIUO">In Penny Lane, there is a barber showing photographs..</p>
<p><sup>Quick brown fox jumps over the lazy dog. </sup></p><p id="b-NzgT3GpkPSdZL_VyV2f">In Penny Lane, there is a barber showing photographs..</p>
1 change: 1 addition & 0 deletions tests/data/json/audio.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
{
"type": "audio",
"attrs": {
"id": "b-NzgT2MAhuSTnpFyo-E3",
"src": "https://getfoobar/audio/sohtdbcmxu-1581683086.mp3",
"caption": "YetAnotherPodcaster"
}
Expand Down
3 changes: 2 additions & 1 deletion tests/data/json/code_block.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
{
"type": "code_block",
"attrs": {
"language": "python"
"language": "python",
"id": "b-NzgT2MAhuSTnpFyo-E4"
},
"content": [
{
Expand Down
1 change: 1 addition & 0 deletions tests/data/json/data_attributes.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
{
"type": "image",
"attrs": {
"id": "b-NzgT2MAhuSTnpFyo-E5",
"src": { "image": "https://placekitten.com/200/301", "fallback": "https://placekitten.com/200/301" },
"alt": "Sleepy Kitten",
"caption": "Cute Kitty",
Expand Down
1 change: 1 addition & 0 deletions tests/data/json/document-pdf.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
{
"type": "document",
"attrs": {
"id": "b-NzgT2MAhuSTnpFyo-E6",
"src": "http://www.africau.edu/images/default/sample.pdf",
"caption": "This is pdf caption.",
"name": "RE_40566006.pdf",
Expand Down
1 change: 1 addition & 0 deletions tests/data/json/embed.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
{
"type": "embed",
"attrs": {
"id": "b-NzgT2MAhuSTnpFyo-E7",
"title": "Extraction | Chris Hemsworth | Official Trailer | Netflix India",
"description": "A hardened mercenary's mission becomes a soul-searching race to survive when he's sent into Bangladesh to rescue a drug lord's kidnapped son.",
"type": "video",
Expand Down
1 change: 1 addition & 0 deletions tests/data/json/heading.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
{
"type": "heading",
"attrs": {
"id": "b-NzgT2MAhuSTnpFyo-E8",
"level": 2
},
"content": [
Expand Down
6 changes: 6 additions & 0 deletions tests/data/json/horizontal_rule.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
{
"type": "doc",
"content": [
{
"type": "horizontal_rule",
"attrs": {
"id": "b-NzgT2MAhuSTnpFyo-E8"
}
},
{
"type": "horizontal_rule"
}
Expand Down
1 change: 1 addition & 0 deletions tests/data/json/image.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
{
"type": "image",
"attrs": {
"id": "b-NzgT2MAhuSTnpFyo-E9",
"src": {
"image": "https://placekitten.com/200/301?text=\"escape me\"",
"fallback": "https://placekitten.com/198/654"
Expand Down
2 changes: 1 addition & 1 deletion tests/data/json/paragraph.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
{
"type": "paragraph",
"attrs": {
"id": "ayZCtf1xgGPZnCVimIUO"
"id": "b-NzgT3GpkPSdZL_VyV2f"
},
"content": [
{
Expand Down
68 changes: 34 additions & 34 deletions tests/test_transform.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,45 +6,45 @@
import tiptapy

tags_to_test = (
# "simple",
# "blockquote",
# "bulletlist",
# "mark_tags",
"simple",
"blockquote",
"bulletlist",
"mark_tags",
"ordered_list",
"paragraph",
"paragraph-is_renderable",
"paragraph-codemark",
"paragraph-escape",
# "image",
# "image-is_renderable",
# "image-missing_caption",
# "image-no_caption",
# "image-mime_type",
# "image-height_width",
# "featuredimage",
# "featuredimage-is_renderable",
# "featuredimage-missing_caption",
# "featuredimage-no_caption",
# "featuredimage-mime_type",
# "featuredimage-height_width",
# "horizontal_rule",
# "embed",
# "embed-missing_caption",
# "embed-no_caption",
# "embed-null_caption",
# "heading",
# "is_renderable",
# "code_block",
# "code_block-is_renderable",
# "audio",
# "audio-no_caption",
# "audio-is_renderable",
# "document-pdf",
# "document-is_renderable",
# "document-sketch",
# "camel-case",
# "data_attributes",
# "xss",
"image",
"image-is_renderable",
"image-missing_caption",
"image-no_caption",
"image-mime_type",
"image-height_width",
"featuredimage",
"featuredimage-is_renderable",
"featuredimage-missing_caption",
"featuredimage-no_caption",
"featuredimage-mime_type",
"featuredimage-height_width",
"horizontal_rule",
"embed",
"embed-missing_caption",
"embed-no_caption",
"embed-null_caption",
"heading",
"is_renderable",
"code_block",
"code_block-is_renderable",
"audio",
"audio-no_caption",
"audio-is_renderable",
"document-pdf",
"document-is_renderable",
"document-sketch",
"camel-case",
"data_attributes",
"xss",
)


Expand Down
2 changes: 1 addition & 1 deletion tiptapy/templates/codeBlock.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
{%- if node.content -%}
{%- set text = node.content[0].text -%}
{%- if text -%}
<div><pre>
<div{{ extract_parent_tag_attrs(node) }}><pre>
{%- if language -%}
<code data-lang="{{language}}">{{text}}</code>
{%- else -%}
Expand Down
2 changes: 1 addition & 1 deletion tiptapy/templates/code_block.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
{%- if node.content -%}
{%- set text = node.content[0].text -%}
{%- if text -%}
<div><pre>
<div{{ extract_parent_tag_attrs(node) }}><pre>
{%- if language -%}
<code data-lang="{{language}}">{{text}}</code>
{%- else -%}
Expand Down
2 changes: 1 addition & 1 deletion tiptapy/templates/embed.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{%- set html = node.attrs.html -%}

{%- set provider_name = node.attrs.provider|default('link')|lower -%}
<div class="embed-wrapper {{provider_name}}-wrapper">
<div class="embed-wrapper {{provider_name}}-wrapper"{{ extract_parent_tag_attrs(node) }}>
{%- for item in node.content -%}
{%- with template=item.type + '.html', node=item -%}
{%- include template -%}
Expand Down
2 changes: 1 addition & 1 deletion tiptapy/templates/extras/audio.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
{%- set audio_player_block = get_audio_player_block() -%}
{%- set src = node.attrs.src|trim -%}

<figure class="audio-player-container">
<figure class="audio-player-container"{{ extract_parent_tag_attrs(node) }}>
{%- if caption -%}
<div><audio src={{src}}></audio>{{audio_player_block}}</div><figcaption>{{caption}}</figcaption>
{%- else -%}
Expand Down
2 changes: 1 addition & 1 deletion tiptapy/templates/extras/document.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
{%- set ext = node.attrs.format|trim -%}
{%- if src and size and fname and ext -%}
{%- set doc_block = get_doc_block(ext, fname, size, src) -%}
<figure class="file-attachment">
<figure class="file-attachment"{{ extract_parent_tag_attrs(node) }}>
{%- if caption -%}
{{doc_block}}<figcaption>{{caption}}</figcaption>
{%- else -%}
Expand Down
2 changes: 1 addition & 1 deletion tiptapy/templates/heading.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<h{{node.attrs.level|default(1)}}>
<h{{node.attrs.level|default(1)}}{{ extract_parent_tag_attrs(node) }}>
{%- for item in node.content -%}
{%- with template=item.type + '.html', node=item -%}
{%- include template -%}
Expand Down
2 changes: 1 addition & 1 deletion tiptapy/templates/horizontalRule.html
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<hr>
<hr{{ extract_parent_tag_attrs(node) }}>
2 changes: 1 addition & 1 deletion tiptapy/templates/horizontal_rule.html
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<hr>
<hr{{ extract_parent_tag_attrs(node) }}>
2 changes: 1 addition & 1 deletion tiptapy/templates/image.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
{%- set fallback_type = url2mime(fallback_url) -%}

{%- if image_url or fallback_url -%}
<figure><picture><source srcset="{{ image_url }}" type="{{ image_type }}"/><source srcset="{{ fallback_url }}" type="{{ fallback_type }}"/><{{ make_img_src(node.attrs) }}/></picture>
<figure{{ extract_parent_tag_attrs(node) }}><picture><source srcset="{{ image_url }}" type="{{ image_type }}"/><source srcset="{{ fallback_url }}" type="{{ fallback_type }}"/><{{ make_img_src(node.attrs) }}/></picture>
{%- if caption -%}
<figcaption>{{ caption }}</figcaption>
{%- endif -%}
Expand Down

0 comments on commit 263fc07

Please sign in to comment.