Skip to content

Commit

Permalink
review change
Browse files Browse the repository at this point in the history
  • Loading branch information
Rajat Singla committed Jun 6, 2024
1 parent 9658340 commit fbe3d69
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 10 deletions.
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": {
"uid": "ayZCtf1xgGPZnCVimIUO"
"id": "ayZCtf1xgGPZnCVimIUO"
},
"content": [
{
Expand Down
4 changes: 2 additions & 2 deletions tiptapy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
get_audio_player_block,
get_doc_block,
make_img_src,
render_block_id,
extract_parent_tag_attrs,
)

__version__ = "0.18.1"
Expand All @@ -27,7 +27,7 @@ def init_env(path, config):
)
# https://stackoverflow.com/a/6038550
env.globals["url2mime"] = url2mime
env.globals["render_block_id"] = render_block_id
env.globals["extract_parent_tag_attrs"] = extract_parent_tag_attrs
env.globals["make_img_src"] = make_img_src
env.globals["handle_links"] = build_link_handler(config)
env.globals["get_audio_player_block"] = get_audio_player_block
Expand Down
17 changes: 11 additions & 6 deletions tiptapy/macros.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,17 @@
from urllib.parse import urlparse


def render_block_id(node):
uid = node.get("attrs", {}).get("uid", "").strip()
if not uid:
return ''

return f' id="{uid}"'
def extract_parent_tag_attrs(node):
allowed_attributes = ("id",)
attrs = node.get("attrs")
return (
"".join(
f' {attr}="{attrs[attr]}"' for attr in allowed_attributes if attr in attrs
)
if attrs
else ""
)


def make_img_src(attrs):
alt = attrs.get("alt", "").strip()
Expand Down
2 changes: 1 addition & 1 deletion tiptapy/templates/paragraph.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{%- if node.content -%}
<p{{ render_block_id(node) }}>
<p{{ extract_parent_tag_attrs(node) }}>
{%- for item in node.content -%}
{%- with template=item.type + '.html', node=item -%}
{%- include template -%}
Expand Down

0 comments on commit fbe3d69

Please sign in to comment.