Merge pull request #146 from inktomi/fix/multiline-text-escape

fix: escape newlines in WireManager.add_text
This commit is contained in:
Eugene Mikhantyev
2026-05-03 21:04:06 +01:00
committed by GitHub
2 changed files with 42 additions and 1 deletions

View File

@@ -1045,7 +1045,15 @@ class WireManager:
) -> bool:
"""Add a free-form text annotation (SCH_TEXT) to a KiCad schematic."""
try:
text_escaped = text.replace("\\", "\\\\").replace('"', '\\"')
# KiCad's parser rejects raw newlines inside quoted string literals,
# so escape them along with backslashes and quotes. Order matters:
# backslashes first, otherwise we double-escape our own escapes.
text_escaped = (
text.replace("\\", "\\\\")
.replace('"', '\\"')
.replace("\n", "\\n")
.replace("\r", "\\r")
)
uid = str(uuid.uuid4())
font_attrs = f"\n\t\t\t\t(size {font_size} {font_size})"
if bold: