Skip to content

Commit

Permalink
Review changes
Browse files Browse the repository at this point in the history
  • Loading branch information
sayanarijit committed Feb 12, 2024
1 parent ced6ea7 commit 1b1cd29
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 11 deletions.
12 changes: 7 additions & 5 deletions tests/test_transform.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,11 @@ class config:
DOMAIN = "python.org"


def build_test_data():
def build_test_data(rebuild_html=False):
"""
Scan data directories and return test data
:param rebuild_html: If True, rebuild the html files
"""
store = {"json": {}, "html": {}}
for data_type in store:
Expand All @@ -67,10 +69,10 @@ def build_test_data():
data = f.read()
store[data_type][file.split(f".{data_type}")[0]] = data

## Use this to (re)generate the html files
# if data_type == "json":
# with open(file_path.replace("json", "html"), "w") as f:
# f.write(tiptapy.BaseDoc(config).render(data))
# Use this to (re)generate the html files
if rebuild_html and data_type == "json":
with open(file_path.replace("json", "html"), "w") as f:
f.write(tiptapy.BaseDoc(config).render(data))

return store["json"], store["html"]

Expand Down
11 changes: 6 additions & 5 deletions tiptapy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,15 @@ def _get_abs_template_path(path_str):
return os.path.join(pkg_dir, path_str)


def escape_recursive(node):
def escape_values_recursive(node):
skip_key = "html" # Skip escaping html values in embeds
if isinstance(node, dict):
for k, v in node.items():
if k != "html":
node[k] = escape_recursive(v)
if k != skip_key:
node[k] = escape_values_recursive(v)
elif isinstance(node, list):
for i, v in enumerate(node):
node[i] = escape_recursive(v)
node[i] = escape_values_recursive(v)
elif isinstance(node, str):
return escape(node)
return node
Expand All @@ -75,5 +76,5 @@ def __init__(self, config):
def render(self, in_data):
in_data = in_data if isinstance(in_data, dict) else json.loads(in_data)
node = in_data if isinstance(in_data, dict) else json.loads(in_data)
node = escape_recursive(node)
node = escape_values_recursive(node)
return self.t.render(node=node)
2 changes: 1 addition & 1 deletion tiptapy/templates/codeBlock.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{%- set language = node.attrs.language|default("") -%}
{%- if node.content -%}
{%- set text node.content[0].text -%}
{%- set text = node.content[0].text -%}
{%- if text -%}
<div><pre>
{%- if language -%}
Expand Down

0 comments on commit 1b1cd29

Please sign in to comment.