From fbe3d69c49a7f628261ca3df6323ab02e2816d76 Mon Sep 17 00:00:00 2001 From: Rajat Singla Date: Thu, 6 Jun 2024 11:16:14 +0530 Subject: [PATCH] review change --- tests/data/json/paragraph.json | 2 +- tiptapy/__init__.py | 4 ++-- tiptapy/macros.py | 17 +++++++++++------ tiptapy/templates/paragraph.html | 2 +- 4 files changed, 15 insertions(+), 10 deletions(-) diff --git a/tests/data/json/paragraph.json b/tests/data/json/paragraph.json index e55f8aa..db9c78b 100644 --- a/tests/data/json/paragraph.json +++ b/tests/data/json/paragraph.json @@ -18,7 +18,7 @@ { "type": "paragraph", "attrs": { - "uid": "ayZCtf1xgGPZnCVimIUO" + "id": "ayZCtf1xgGPZnCVimIUO" }, "content": [ { diff --git a/tiptapy/__init__.py b/tiptapy/__init__.py index 279d0b1..489db21 100644 --- a/tiptapy/__init__.py +++ b/tiptapy/__init__.py @@ -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" @@ -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 diff --git a/tiptapy/macros.py b/tiptapy/macros.py index d5c6e0c..713d78b 100644 --- a/tiptapy/macros.py +++ b/tiptapy/macros.py @@ -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() diff --git a/tiptapy/templates/paragraph.html b/tiptapy/templates/paragraph.html index 49bba09..d07a5e8 100644 --- a/tiptapy/templates/paragraph.html +++ b/tiptapy/templates/paragraph.html @@ -1,5 +1,5 @@ {%- if node.content -%} - + {%- for item in node.content -%} {%- with template=item.type + '.html', node=item -%} {%- include template -%}