#214 add data-tag to local script elements, untested
This commit is contained in:
parent
df495997f8
commit
339b7d75db
1 changed files with 5 additions and 3 deletions
|
@ -30,11 +30,12 @@ function getAllScriptOffsets(htmlFile) {
|
||||||
} else {
|
} else {
|
||||||
endFilenameInd = htmlFile.indexOf('.js', ind + startTag.length + 3);
|
endFilenameInd = htmlFile.indexOf('.js', ind + startTag.length + 3);
|
||||||
filename = htmlFile.substring(ind + startTag.length, endFilenameInd);
|
filename = htmlFile.substring(ind + startTag.length, endFilenameInd);
|
||||||
lineOffset = htmlFile.substring(0, ind).split('\n').length;
|
lineOffset = htmlFile.substring(0, ind).split('\n').length - 1;
|
||||||
offs.push([lineOffset, filename]);
|
offs.push([lineOffset, filename]);
|
||||||
lastInd = ind + 1;
|
lastInd = ind + 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
console.log(offs);
|
||||||
return offs;
|
return offs;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -198,7 +199,7 @@ class PreviewFrame extends React.Component {
|
||||||
scriptOffs = getAllScriptOffsets(sketchDocString);
|
scriptOffs = getAllScriptOffsets(sketchDocString);
|
||||||
const consoleErrorsScript = sketchDoc.createElement('script');
|
const consoleErrorsScript = sketchDoc.createElement('script');
|
||||||
consoleErrorsScript.innerHTML = hijackConsoleErrorsScript(JSON.stringify(scriptOffs));
|
consoleErrorsScript.innerHTML = hijackConsoleErrorsScript(JSON.stringify(scriptOffs));
|
||||||
sketchDoc.head.appendChild(consoleErrorsScript);
|
sketchDoc.body.appendChild(consoleErrorsScript);
|
||||||
|
|
||||||
return `<!DOCTYPE HTML>\n${sketchDoc.documentElement.outerHTML}`;
|
return `<!DOCTYPE HTML>\n${sketchDoc.documentElement.outerHTML}`;
|
||||||
}
|
}
|
||||||
|
@ -282,6 +283,7 @@ class PreviewFrame extends React.Component {
|
||||||
if (resolvedFile.url) {
|
if (resolvedFile.url) {
|
||||||
script.setAttribute('src', resolvedFile.url);
|
script.setAttribute('src', resolvedFile.url);
|
||||||
} else {
|
} else {
|
||||||
|
script.setAttribute('data-tag', `${startTag}${resolvedFile.name}`);
|
||||||
script.removeAttribute('src');
|
script.removeAttribute('src');
|
||||||
script.innerHTML = resolvedFile.content; // eslint-disable-line
|
script.innerHTML = resolvedFile.content; // eslint-disable-line
|
||||||
}
|
}
|
||||||
|
@ -310,7 +312,7 @@ class PreviewFrame extends React.Component {
|
||||||
} else {
|
} else {
|
||||||
const style = sketchDoc.createElement('style');
|
const style = sketchDoc.createElement('style');
|
||||||
style.innerHTML = `\n${resolvedFile.content}`;
|
style.innerHTML = `\n${resolvedFile.content}`;
|
||||||
sketchDoc.head.appendChild(style);
|
sketchDoc.body.appendChild(style);
|
||||||
css.parentElement.removeChild(css);
|
css.parentElement.removeChild(css);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue