drawio-diagrams
Drawio Diagrams
Overview
Use this skill to safely automate draw.io diagram work without relying on manual GUI edits. Use bundled commands for page summaries, filtered cell discovery, validation, theme transforms, storage conversion, and targeted/batch cell edits.
Use this skill especially when a diagram renders differently across platforms (for example Windows vs Mac) or when dark-mode/theme defaults introduce unexpected backgrounds, icon fills, or label boxes.
Quick start
- Inspect structure first.
- Scan for theme-sensitive tokens before editing.
- Discover candidate cells with filtered
list-cells. - Edit into a new output file (or in-place +
--backup). - Validate structure and style.
- Convert storage mode only when needed.
python3 script summary <file.drawio>
rg -n "light-dark|imageBackground=default|var\\(--ge-dark-color|background-color:" <file.drawio>
python3 script list-cells <file.drawio> --page 1 --vertex --min-width 400
python3 script validate <file.drawio> --style
Core workflow
- Run
summaryto identify page names, storage mode, and cell counts. - Scan the file for theme-sensitive tokens with
rgand targetedlist-cellsqueries before editing. - Run
list-cellsto find target ids by page/type/style/geometry. - Apply targeted changes with
set-cellor batch changes withset-cells. - If the issue is cross-platform or light/dark rendering drift, run
normalize-lightbefore manual cleanups. - For large neutral-color shifts, use
apply-theme --theme light|dark. - Run
validate --styleon the edited output. - Optionally run
convert-storageif the output must be all compressed or all uncompressed.
Commands
summary
Show page-level structure and counts.
python3 script summary diagram.drawio
python3 script summary diagram.drawio --json
list-cells
List cells with optional filters so edits can be scoped precisely.
python3 script list-cells diagram.drawio --page 5 --vertex --min-width 500
python3 script list-cells diagram.drawio --style-contains fillColor=#000000 --json
python3 script list-cells diagram.drawio --edge --value-contains "Metrics"
validate
Validate that pages decode and edge references remain consistent. Optional style lint checks cover contrast, edge label background hygiene, and theme-compatibility risks.
python3 script validate diagram.drawio
python3 script validate diagram.drawio --style
python3 script validate diagram.drawio --style --fail-on-style
Validation checks:
- XML parses correctly
- each page payload decodes/parses
- duplicate
mxCellids per page - edge
source/targetids exist on the same page - optional style warnings (
--style):- low text contrast where parseable colors exist
- non-transparent edge-label backgrounds
- edge labels missing explicit
labelBackgroundColor=none - edge labels missing explicit
fontColor light-dark(...)in style attributeslight-dark(...)orvar(--ge-dark-color...)inside HTML label content- inline HTML
background-color:declarations that can render as boxes on some platforms imageBackground=default- transparent
textcells with no explicitfontColor - shaped cells with no explicit
fillColor/strokeColorthat may inherit platform theme defaults
set-cell
Edit a single mxCell by id (optionally limit to one page).
python3 script set-cell in.drawio out.drawio \
--cell-id k_x_UaeQuVGz606EVGA7-25 \
--append-value " [Updated]"
python3 script set-cell in.drawio out.drawio \
--cell-id k_x_UaeQuVGz606EVGA7-25 \
--set-style fontSize=24 \
--set-style fontColor=#003366 \
--remove-style gradientColor
python3 script set-cell in.drawio out.drawio \
--cell-id k_x_UaeQuVGz606EVGA7-25 \
--set-style fontSize=24 \
--dry-run
python3 script set-cell in.drawio in.drawio \
--cell-id k_x_UaeQuVGz606EVGA7-25 \
--set-style fillColor=#ffffff \
--in-place --backup
set-cells
Batch-edit multiple ids in one atomic write.
python3 script set-cells in.drawio out.drawio \
--cell-id id-1 --cell-id id-2 --cell-id id-3 \
--set-style fillColor=#ffffff \
--set-style fontColor=#000000
python3 script set-cells in.drawio in.drawio \
--cell-id id-1 --cell-id id-2 \
--set-style strokeColor=#000000 \
--in-place --backup
apply-theme
Apply a neutral light/dark transform to selected pages (background + neutral fills/strokes/fonts + edge label cleanup).
python3 script apply-theme in.drawio out.drawio --theme light
python3 script apply-theme in.drawio in.drawio --theme dark --page 2 --in-place --backup
python3 script apply-theme in.drawio out.drawio --theme light --dry-run
normalize-light
Normalize theme-sensitive content for light-mode and cross-platform rendering. This is the fastest first pass when a diagram looked fine on Windows but started showing dark backgrounds or boxed labels on Mac.
What it does:
- sets page backgrounds to
#ffffff - resolves
light-dark(...)andvar(...)to fixed light-mode values - strips inline HTML
background-color:declarations from label content - converts
imageBackground=defaulttoimageBackground=none - makes edge labels explicitly transparent (
labelBackgroundColor=none,fillColor=none,strokeColor=none) - assigns
fontColor=#000000to transparenttextlabels that do not already define one
python3 script normalize-light in.drawio out.drawio
python3 script normalize-light in.drawio in.drawio --in-place --backup
python3 script normalize-light in.drawio out.drawio --page 2 --dry-run
convert-storage
Convert page storage mode across the file.
python3 script convert-storage in.drawio out.drawio --storage compressed
python3 script convert-storage in.drawio out.drawio --storage uncompressed
python3 script convert-storage in.drawio in.drawio --storage compressed --in-place
python3 script convert-storage in.drawio in.drawio --storage compressed --in-place --backup
Editing rules
- Prefer targeted edits by
mxCell@id. - Scan for
light-dark,imageBackground=default,var(--ge-dark-color, and inlinebackground-color:before visual edits. - Avoid broad search/replace on full XML.
- Prefer writing to a new output path; if editing in-place, use
--backup. - Use
--dry-runbefore high-impact edits. - Use
--forceonly when intentionally replacing an existing output file. - Preserve page storage mode unless conversion is required.
- Validate after each edit batch (
validate --stylefor visual changes). - When labels use HTML in
@value, inspect and edit both the style string and the HTML payload; visual bugs often live in the HTML, not only instyle=....
Visual Refactor Checklist
Use this checklist for broad style changes (background/theme/contrast updates):
- Enumerate affected pages with
summary. - Scan for theme-sensitive tokens with
rgandlist-cells:light-dark,imageBackground=default,var(--ge-dark-color,background-color: - Locate candidate containers via
list-cellsgeometry filters (--min-width,--min-height). - Locate dependent labels/arrows via
list-cellsfilters (--edge,--style-contains,--value-contains). - If the issue is broad light-mode drift, run
normalize-light --dry-runfirst. - Run edits in one batch (
set-cells) where possible; avoid many single writes. - Use
--dry-runfirst. - If in-place, enable
--backup. - Run
validate --style. - Re-open diagram and visually verify target page(s).
Theme Compatibility
Use this workflow when a diagram changed appearance after moving between Windows and Mac or after draw.io started honoring dark-mode defaults:
- Run
summaryand confirm page storage/backgrounds. - Scan the raw file:
rg -n "light-dark|imageBackground=default|var\\(--ge-dark-color|background-color:" diagram.drawio - Run focused queries:
python3 script list-cells diagram.drawio --style-contains imageBackground=defaultpython3 script list-cells diagram.drawio --value-contains "light-dark(" - Run
validate --styleto surface theme-risk warnings. - Run
normalize-lightfor a broad light-mode cleanup. - Apply targeted
set-cell/set-cellsedits for any remaining exceptions.
Common offenders:
imageBackground=defaulton icon/image cellslight-dark(...)in style values or HTML labelsvar(--ge-dark-color, ...)in HTML labels- edge labels without
labelBackgroundColor=none textlabels with transparent fill and no explicitfontColor- shaped cells without explicit
fillColor/strokeColor - HTML spans with inline
background-color:that show up as boxes on another platform
References
Read references/format-and-safety.md when you need details on:
- draw.io compression/decompression pipeline
- mxGraph model semantics
- UI paths for manual XML/style editing
- authoritative source links