Skip to content

Support pcb note elements in footprint generation#15

Merged
seveibar merged 2 commits into
mainfrom
codex/add-support-for-pcb_note_-elements
Oct 16, 2025
Merged

Support pcb note elements in footprint generation#15
seveibar merged 2 commits into
mainfrom
codex/add-support-for-pcb_note_-elements

Conversation

@seveibar
Copy link
Copy Markdown
Contributor

Summary

  • convert pcb_note_* circuit JSON elements into their corresponding <pcbnote*> JSX primitives during footprint generation
  • add a regression test covering pcb note text, rect, path, line, and dimension mappings

Testing

  • bunx tsc --noEmit
  • bun test

https://chatgpt.com/codex/tasks/task_b_68f069c999e0832eaa2dbe021e4ff8c9

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting

Comment on lines +119 to +130
for (const noteText of noteTexts) {
const anchorPosition = noteText.anchor_position ?? { x: 0, y: 0 }
const anchorAlignment = noteText.anchor_alignment ?? "center"
const font = noteText.font ?? "tscircuit2024"
const fontSize = noteText.font_size ?? 0
const colorAttr = noteText.color ? ` color="${noteText.color}"` : ""

const rawText = String(noteText.text ?? "")
const escapedText = rawText.replace(/"/g, '\\"')

elementStrings.push(
`<pcbnotetext pcbX={${anchorPosition.x}} pcbY={${anchorPosition.y}} anchorAlignment="${anchorAlignment}" font="${font}" fontSize={${fontSize}} text="${escapedText}"${colorAttr} />`,
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Escape note text contents before embedding into JSX

The conversion logic escapes only double quotes before writing noteText.text into the text="…" attribute, but values such as "A<B" or "A&B" are not escaped. When a note contains </>/&, the generated TSX will be syntactically invalid because the attribute value terminates prematurely or introduces an entity. Consider encoding the string with JSON.stringify or replacing these characters so note texts containing comparison symbols or ampersands still generate valid JSX.

Useful? React with 👍 / 👎.

Comment on lines +223 to +225
if (noteDimension.text !== undefined) {
const escapedText = String(noteDimension.text).replace(/"/g, '\\"')
attrs.push(`text="${escapedText}"`)
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Escape dimension label text before embedding into JSX

The dimension loop performs the same quote-only escaping for noteDimension.text and embeds it directly into text="…". If a dimension label contains characters like <, > or &, the generated JSX becomes invalid and convertCircuitJsonToTscircuit will emit code that fails to compile. The label should be fully escaped (e.g., via JSON.stringify or manual replacement of <, >, &) before being injected.

Useful? React with 👍 / 👎.

Comment on lines +126 to +127
const rawText = String(noteText.text ?? "")
const escapedText = rawText.replace(/"/g, '\\"')
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Backslashes in text are not escaped, which will break the generated TSX syntax. If the text contains a backslash (e.g., "test\value"), the generated code will have text="test\value" where the backslash could escape the closing quote or create invalid escape sequences.

Fix by escaping backslashes before quotes:

const rawText = String(noteText.text ?? "")
const escapedText = rawText.replace(/\\/g, '\\\\').replace(/"/g, '\\"')
Suggested change
const rawText = String(noteText.text ?? "")
const escapedText = rawText.replace(/"/g, '\\"')
const rawText = String(noteText.text ?? "")
const escapedText = rawText.replace(/\\/g, '\\\\').replace(/"/g, '\\"')

Spotted by Graphite Agent

Fix in Graphite


Is this helpful? React 👍 or 👎 to let us know.

This comment came from an experimental review—please leave feedback if it was helpful/unhelpful. Learn more about experimental comments here.

}

if (noteDimension.text !== undefined) {
const escapedText = String(noteDimension.text).replace(/"/g, '\\"')
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same backslash escaping issue as noteText. Backslashes in dimension text are not escaped before embedding in the generated TSX string.

Fix by escaping backslashes before quotes:

const escapedText = String(noteDimension.text).replace(/\\/g, '\\\\').replace(/"/g, '\\"')
Suggested change
const escapedText = String(noteDimension.text).replace(/"/g, '\\"')
const escapedText = String(noteDimension.text).replace(/\\/g, '\\\\').replace(/"/g, '\\"')

Spotted by Graphite Agent

Fix in Graphite


Is this helpful? React 👍 or 👎 to let us know.

This comment came from an experimental review—please leave feedback if it was helpful/unhelpful. Learn more about experimental comments here.

@seveibar seveibar merged commit 67698fd into main Oct 16, 2025
3 checks passed
@seveibar seveibar deleted the codex/add-support-for-pcb_note_-elements branch October 16, 2025 04:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant