Skip to content

Commit

Permalink
test script tag fix
Browse files Browse the repository at this point in the history
  • Loading branch information
squi-ddy committed Sep 18, 2023
1 parent 8989cc1 commit 2867bf6
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 5 deletions.
3 changes: 2 additions & 1 deletion frontend/src/components/notebookViewer/BlockOutput.vue
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<v-col cols="12" v-if="graphic" class="cell-content output-display">
<img v-if="'image/png' in output.data" alt="Image Error"
:src="b64ToUrl(normaliseJupyterOutput(output.data['image/png']),'image/png')"/>
<div v-if="'text/html' in output.data" v-html="output.data['text/html'].join('')"></div>
<HTMLOutput v-if="'text/html' in output.data" :html="output.data['text/html'].join('')"></HTMLOutput>
</v-col>
</template>
<pre v-else-if="output.output_type==='error'" class="cell-content output-err"
Expand All @@ -42,6 +42,7 @@
import {Component, Prop, Vue} from "vue-property-decorator";
import {Cell} from "@/types/shims/shims-nbformat-v4";
import Convert from "ansi-to-html";
import HTMLOutput from "./HTMLOutput.vue";
const convert = new Convert();
@Component
Expand Down
38 changes: 38 additions & 0 deletions frontend/src/components/notebookViewer/HTMLOutput.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<template>
<div v-html="html" ref="htmlDiv"></div>
</template>

<script lang="ts">
import {Component, Prop, Vue} from "vue-property-decorator";
@Component
export default class HTMLOutput extends Vue {
name = "HTMLOutput"
@Prop(String) readonly html!: string;
htmlDiv!: HTMLDivElement;
recurseDescendants (node: Element) {
for (var i = 0; i < node.children.length; i++) {
var child = node.children[i];
this.recurseDescendants(child);
if (child.tagName === 'SCRIPT') {
console.log(child.innerHTML);
eval?.(child.innerHTML);
child.remove();
i--;
}
}
}
mounted() {
this.recurseDescendants(this.htmlDiv);
}
}
</script>

<style scoped>
</style>
11 changes: 7 additions & 4 deletions frontend/src/mixins/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,17 +120,20 @@ export function equals<T extends number | string>(a: T[], b: T[]) {

export function addPyScript() {
if (!document.getElementById('pyscript')) {
const env = document.createElement('py-config');
env.innerHTML = 'packages = ["numpy", "matplotlib", "plotly"]'
const env = document.createElement('py-env');
env.innerHTML = `
- numpy
- matplotlib
`
document.head.appendChild(env);
const script = document.createElement('script');
script.id = 'pyscript';
script.defer = true
script.src = 'https://pyscript.net/latest/pyscript.js';
script.src = 'https://pyscript.net/alpha/pyscript.js';
document.head.appendChild(script);
const styles = document.createElement('style');
styles.innerHTML = `
.v-application.theme--dark .editor-box .cm-gutters{
.v-application.theme--dark .editor-box .cm-gutters {
background-color: #999;
color: #f5f5f5;
}
Expand Down

0 comments on commit 2867bf6

Please # to comment.