fix workflow embedding w/ unicode characters

This commit is contained in:
thot-experiment 2025-05-08 09:32:55 -07:00
parent c854ba17ed
commit 8602052fdb

View File

@ -266,14 +266,18 @@ class SaveSVGNode:
if metadata_json: if metadata_json:
# Create metadata element with CDATA section # Create metadata element with CDATA section
metadata_element = f""" <metadata> metadata_element = f""" <metadata>
<![CDATA[ <![CDATA[
{metadata_json} {metadata_json}
]]> ]]>
</metadata> </metadata>
""" """
# Insert metadata after opening svg tag using regex # Insert metadata after opening svg tag using regex with a replacement function
# import re # Already imported at the top def replacement(match):
svg_content = re.sub(r'(<svg[^>]*>)', r'\1\n' + metadata_element, svg_content) # match.group(1) contains the captured <svg> tag
return match.group(1) + '\n' + metadata_element
# Apply the substitution
svg_content = re.sub(r'(<svg[^>]*>)', replacement, svg_content, flags=re.UNICODE)
# Write the modified SVG to file # Write the modified SVG to file
with open(os.path.join(full_output_folder, file), 'wb') as svg_file: with open(os.path.join(full_output_folder, file), 'wb') as svg_file: