Skip to content

Commit ba7672a

Browse files
committed
proper implementation for the viewer
1 parent fc47817 commit ba7672a

File tree

5 files changed

+26
-15
lines changed

5 files changed

+26
-15
lines changed

package.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,14 @@
7474
"mimeTypes": [
7575
"ms-vscode.r-notebook/table"
7676
]
77+
},
78+
{
79+
"id": "r-notebook-viewer-renderer",
80+
"displayName": "Notebook Viewer Render",
81+
"entrypoint": "./dist/viewerRenderer.js",
82+
"mimeTypes": [
83+
"ms-vscode.r-notebook/viewer"
84+
]
7785
}
7886
],
7987
"viewsContainers": {

samples/test1.rmd

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ df = data.frame(a = c(1,2,3,4), b = c(10, 20, 13, 1))
88
library(ggplot2)
99
library(plotly)
1010
11-
df
11+
ggplotly(ggplot(df, aes(a, b)) + geom_point())
1212
```
1313
```{r}
14-
ggplot(df, aes(a, b)) + geom_point()
14+
ggplotly(ggplot(df, aes(a, b)) + geom_point())
1515
1616
```
1717
```{r}
Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,15 @@
1-
const notebookApi = acquireNotebookRendererApi("r-notebook-table-renderer");
1+
const notebookApi = acquireNotebookRendererApi("r-notebook-viewer-renderer");
22

33

44
notebookApi.onDidCreateOutput((evt) => {
55
const output = evt.output.data[evt.mimeType];
6-
evt.element.innerHTML =
6+
const iframe = document.createElement("iframe");
7+
iframe.style.border = "0";
8+
iframe.style.width = "90vw"
9+
iframe.style.minHeight = "30vw"
10+
iframe.sandbox.add("allow-scripts");
11+
iframe.sandbox.add("allow-forms");
12+
iframe.sandbox.add("allow-same-origin");
13+
iframe.srcdoc = output
14+
evt.element.appendChild(iframe)
715
});

src/extension/notebook.ts

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -341,17 +341,11 @@ export class RNotebookProvider implements vscode.NotebookContentProvider, vscode
341341
const html = (await vscode.workspace.fs.readFile(vscode.Uri.parse(response.result))).toString();
342342
const htmlDir = dirname(response.result)
343343
const htmlInline = await inlineAll(html, htmlDir)
344-
const htmlWrapped = `
345-
<iframe id="plotly" frameborder="0" sandbox="allow-scripts allow-forms allow-same-origin"></iframe>
346-
<script>
347-
var iframe = document.getElementById("plotly")
348-
iframe.srcdoc = unescape("${escape(htmlInline)}")
349-
</script>
350-
`
344+
351345
return {
352346
outputKind: vscode.CellOutputKind.Rich,
353347
data: {
354-
'text/html': htmlWrapped
348+
'ms-vscode.r-notebook/viewer': htmlInline
355349
},
356350
}
357351
}

webpack.config.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,8 @@ const extensionConfig = {
6464
const clientConfig = {
6565
target: 'web',
6666
entry: {
67-
"tableRenderer": "./src/client/renderers/tableRenderer.tsx"
67+
"tableRenderer": "./src/client/renderers/tableRenderer.tsx",
68+
"viewerRenderer": "./src/client/renderers/viewerRenderer.tsx"
6869
},
6970
output: {
7071
// the bundle is stored in the 'dist' folder (check package.json), 📖 -> https://webpack.js.org/configuration/output/
@@ -108,5 +109,5 @@ const clientConfig = {
108109
]
109110
}
110111

111-
// module.exports = [extensionConfig, clientConfig]
112-
module.exports = [clientConfig]
112+
module.exports = [extensionConfig, clientConfig]
113+
// module.exports = [clientConfig]

0 commit comments

Comments
 (0)