'How to display one's own UI in custom notebooks?
I am planning to create a custom notebook that will have it's own UI instead of using Jupyter styled notebooks. Totally different UI. Almost like an app contained inside vscode.
extension.js
// The module 'vscode' contains the VS Code extensibility API
// Import the module and reference it with the alias vscode in your code below
import * as vscode from "vscode";
import type { ActivationFunction } from "vscode-notebook-renderer";
// This method is called when your extension is activated
// your extension is activated the very first time the command is executed
export const activate: ActivationFunction = (context) => ({
renderOutputItem(data, element) {
element.innerText = `<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Document</title>
</head>
<body>
<p>Hello World</p>
</body>
</html>`;
},
});
// This method is called when your extension is deactivated
export function deactivate() {}
package.json
{
"name": "grocery-book",
"displayName": "Grocery Book",
"description": "",
"version": "0.0.1",
"engines": {
"vscode": "^1.64.0"
},
"keywords": [
"notebookRenderer"
],
"categories": [
"Other"
],
"activationEvents": [],
"main": "./out/extension/extension.js",
"browser": "./out/extension/extension.web.js",
"contributes": {
"notebooks": [
{
"type": "grocery-book",
"displayName": "Grocery Book",
"selector": [
{
"filenamePattern": "*.grocery-book"
}
]
}
],
"notebookRenderer": [
{
"id": "grocery-book",
"entrypoint": "./out/client/index.js",
"displayName": "Grocery Book",
"mimeTypes": [
"x-application/grocery-book"
]
}
]
},
"scripts": {
"vscode:prepublish": "npm run compile",
"compile": "webpack --mode production",
"lint": "eslint src --ext ts",
"watch": "webpack --mode development --watch",
"pretest": "webpack --mode development && npm run lint",
"test": "node ./out/test/runTest.js"
},
"devDependencies": {
"@types/glob": "^7.2.0",
"@types/mocha": "^9.0.0",
"@types/node": "14.x",
"@types/webpack-env": "^1.16.3",
"@typescript-eslint/eslint-plugin": "^5.9.1",
"@typescript-eslint/parser": "^5.9.1",
"@types/vscode-notebook-renderer": "^1.57.8",
"@types/vscode": "^1.64.0",
"css-loader": "^4.2.0",
"eslint": "^8.6.0",
"fork-ts-checker-webpack-plugin": "^5.0.14",
"glob": "^7.2.0",
"mocha": "^9.1.3",
"style-loader": "^1.2.1",
"ts-loader": "^9.2.6",
"typescript": "^4.5.4",
"vscode-notebook-error-overlay": "^1.0.1",
"@vscode/test-electron": "^2.0.3",
"util": "^0.12.4",
"webpack": "^5.66.0",
"webpack-cli": "^4.9.1"
}
}
Afterwards, when I create n.grocerybook, it just shows a loading bar like this,
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|

