Skip to content

Commit 6ec0355

Browse files
committed
feat(swift-export): add code highlight for console
1 parent 5811fc6 commit 6ec0355

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

src/executable-code/executable-fragment.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -504,6 +504,24 @@ export default class ExecutableFragment extends ExecutableCodeTemplate {
504504

505505
state.exception = null;
506506
this.update(state);
507+
508+
if (targetPlatform === TargetPlatforms.SWIFT_EXPORT) {
509+
const code = this.nodes[0]
510+
.querySelector(SELECTORS.JS_CODE_OUTPUT_EXECUTOR)
511+
.querySelector('.result-code');
512+
513+
if (code) {
514+
CodeMirror(
515+
(elt) => code.parentNode.replaceChild(elt, code),
516+
{
517+
mode: 'swift',
518+
readOnly: 'nocursorgit st',
519+
theme: this.state.theme,
520+
value: code.innerText,
521+
},
522+
);
523+
}
524+
}
507525
});
508526
}
509527
},

src/js-executor/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ export default class JsExecutor {
3838
onError,
3939
) {
4040
if (platform === TargetPlatforms.SWIFT_EXPORT) {
41-
return `<span class="standard-output ${theme}">${jsCode}</span>`;
41+
return `<span class="standard-output ${theme}"><div class="result-code">${jsCode}</span>`;
4242
}
4343
if (platform === TargetPlatforms.CANVAS) {
4444
this.iframe.style.display = 'block';

0 commit comments

Comments
 (0)