@@ -108,6 +108,38 @@ export const generateFragmentFromHtml = (html: string): WebstudioFragment => {
108
108
} ;
109
109
110
110
const convertElementToInstance = ( node : ElementNode ) => {
111
+ if ( node . tagName === "svg" && node . sourceCodeLocation ) {
112
+ const { startCol, startOffset, endOffset } = node . sourceCodeLocation ;
113
+ const indent = startCol - 1 ;
114
+ const htmlFragment = html
115
+ . slice ( startOffset , endOffset )
116
+ // try to preserve indentation
117
+ . split ( "\n" )
118
+ . map ( ( line , index ) => {
119
+ if ( index > 0 && / ^ \s + $ / . test ( line . slice ( 0 , indent ) ) ) {
120
+ return line . slice ( indent ) ;
121
+ }
122
+ return line ;
123
+ } )
124
+ . join ( "\n" ) ;
125
+ const instance : Instance = {
126
+ type : "instance" ,
127
+ id : getNewId ( ) ,
128
+ component : "HtmlEmbed" ,
129
+ children : [ ] ,
130
+ } ;
131
+ instances . set ( instance . id , instance ) ;
132
+ const name = "code" ;
133
+ const codeProp : Prop = {
134
+ id : `${ instance . id } :${ name } ` ,
135
+ instanceId : instance . id ,
136
+ name,
137
+ type : "string" ,
138
+ value : htmlFragment ,
139
+ } ;
140
+ props . push ( codeProp ) ;
141
+ return { type : "id" as const , value : instance . id } ;
142
+ }
111
143
if ( ! tags . includes ( node . tagName ) ) {
112
144
return ;
113
145
}
@@ -196,7 +228,10 @@ export const generateFragmentFromHtml = (html: string): WebstudioFragment => {
196
228
return { type : "id" as const , value : instance . id } ;
197
229
} ;
198
230
199
- const documentFragment = parseFragment ( html , { scriptingEnabled : false } ) ;
231
+ const documentFragment = parseFragment ( html , {
232
+ scriptingEnabled : false ,
233
+ sourceCodeLocationInfo : true ,
234
+ } ) ;
200
235
const children : Instance [ "children" ] = [ ] ;
201
236
for ( const childNode of documentFragment . childNodes ) {
202
237
if ( defaultTreeAdapter . isElementNode ( childNode ) ) {
0 commit comments