Skip to content

2feat: Set exported SVG tag ID to its source layer name#3530

Open
theaniketgiri wants to merge 1 commit intoGraphiteEditor:masterfrom
theaniketgiri:feature/svg-export-layer-id
Open

2feat: Set exported SVG tag ID to its source layer name#3530
theaniketgiri wants to merge 1 commit intoGraphiteEditor:masterfrom
theaniketgiri:feature/svg-export-layer-id

Conversation

@theaniketgiri
Copy link
Copy Markdown
Contributor

Implements #2879: When exporting artwork as SVG, group elements ( tags) now include an 'id' attribute set to the layer's display name.

Changes:

  • Add node_names HashMap to RenderParams and RenderConfig to pass layer names from editor to rendering system
  • Add sanitize_svg_id() to convert layer names to valid SVG IDs:
    • Replaces spaces and colons with underscores
    • Strips invalid XML Name characters
    • Ensures ID starts with letter or underscore
  • Add make_unique_svg_id() to handle duplicate names with _2, _3 suffixes
  • Modify Table::render_svg() to add id attribute during export
  • Collect layer names recursively including nested layers/groups
  • Skip default 'Untitled Layer' and 'Untitled Node' names
  • Add comprehensive unit tests for ID sanitization and deduplication

Example: A layer named 'my:square' exports as
Duplicate names get suffixes: 'Layer', 'Layer_2', 'Layer_3'

Closes #2879

Implements GraphiteEditor#2879: When exporting artwork as SVG, group elements (<g> tags)
now include an 'id' attribute set to the layer's display name.

Changes:
- Add node_names HashMap to RenderParams and RenderConfig to pass layer
  names from editor to rendering system
- Add sanitize_svg_id() to convert layer names to valid SVG IDs:
  - Replaces spaces and colons with underscores
  - Strips invalid XML Name characters
  - Ensures ID starts with letter or underscore
- Add make_unique_svg_id() to handle duplicate names with _2, _3 suffixes
- Modify Table<Graphic>::render_svg() to add id attribute during export
- Collect layer names recursively including nested layers/groups
- Skip default 'Untitled Layer' and 'Untitled Node' names
- Add comprehensive unit tests for ID sanitization and deduplication

Example: A layer named 'my:square' exports as <g id='my_square'>
Duplicate names get suffixes: 'Layer', 'Layer_2', 'Layer_3'

Closes GraphiteEditor#2879
.filter_map(|(node_id, _, network_path)| {
let name = document.network_interface.display_name(node_id, &network_path);
// Skip default "Untitled Layer" and "Untitled Node" names
if name.starts_with("Untitled") {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This would skip any user-named layer starting with "Untitled"

@Keavon Keavon force-pushed the master branch 6 times, most recently from d6228da to e58c1de Compare March 16, 2026 23:03
@Keavon Keavon force-pushed the master branch 5 times, most recently from 9b97ab7 to 2e842cb Compare March 19, 2026 11:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Set exported SVG tag ID to its source layer name

2 participants