(xml: string)
| 113 | * @returns Full mxfile-wrapped XML string |
| 114 | */ |
| 115 | export function wrapWithMxFile(xml: string): string { |
| 116 | if (!xml) { |
| 117 | return `<mxfile><diagram name="Page-1" id="page-1"><mxGraphModel><root><mxCell id="0"/><mxCell id="1" parent="0"/></root></mxGraphModel></diagram></mxfile>` |
| 118 | } |
| 119 | |
| 120 | // Already has full structure |
| 121 | if (xml.includes("<mxfile")) { |
| 122 | return xml |
| 123 | } |
| 124 | |
| 125 | // Has mxGraphModel but not mxfile |
| 126 | if (xml.includes("<mxGraphModel")) { |
| 127 | return `<mxfile><diagram name="Page-1" id="page-1">${xml}</diagram></mxfile>` |
| 128 | } |
| 129 | |
| 130 | // Just <root> content - extract inner content and wrap fully |
| 131 | const rootContent = xml.replace(/<\/?root>/g, "").trim() |
| 132 | return `<mxfile><diagram name="Page-1" id="page-1"><mxGraphModel><root>${rootContent}</root></mxGraphModel></diagram></mxfile>` |
| 133 | } |
| 134 | |
| 135 | /** |
| 136 | * Replace nodes in a Draw.io XML diagram |
no outgoing calls
no test coverage detected