From 8602052fdbea3d3d6e956327fccd101ae6d03146 Mon Sep 17 00:00:00 2001 From: thot-experiment Date: Thu, 8 May 2025 09:32:55 -0700 Subject: [PATCH] fix workflow embedding w/ unicode characters --- comfy_extras/nodes_images.py | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/comfy_extras/nodes_images.py b/comfy_extras/nodes_images.py index 7a3c26b20..77c305619 100644 --- a/comfy_extras/nodes_images.py +++ b/comfy_extras/nodes_images.py @@ -266,14 +266,18 @@ class SaveSVGNode: if metadata_json: # Create metadata element with CDATA section metadata_element = f""" - - -""" - # Insert metadata after opening svg tag using regex - # import re # Already imported at the top - svg_content = re.sub(r'(]*>)', r'\1\n' + metadata_element, svg_content) + + + """ + # Insert metadata after opening svg tag using regex with a replacement function + def replacement(match): + # match.group(1) contains the captured tag + return match.group(1) + '\n' + metadata_element + + # Apply the substitution + svg_content = re.sub(r'(]*>)', replacement, svg_content, flags=re.UNICODE) # Write the modified SVG to file with open(os.path.join(full_output_folder, file), 'wb') as svg_file: