microsoft / microsoft/vscode-notebook-renderers
Pull request #245 to fix issue #17116 mentioned in jupyter-notebook repo gives too much output
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 140
- Forks
- 44
- Avg merge
- 12d 9h
- Merged PRs (30d)
- 4
Description
I reported https://github.com/microsoft/vscode-jupyter/issues/17116 for the vscode-jupyter plugin stating that the element variable is not exposed in javascript magic environment. It was fixed in this pull request.
https://github.com/microsoft/vscode-notebook-renderers/pull/245
And indeed output now appears but additionally some source code is output.
Following example:
%%js //the next line is only necessary in jupyter notebooks
element.setAttribute('style', 'white-space: pre;');console.log=function(text){element.textContent+=text+"\n"}
let age=42 //type annotations are not available in javascript you need to use typescript
//that is translated into javascript by a compiler
console.log("I am "+age+" old\n")
output:
(function(){
let gotToUserScript = false;
try {
// Required by JS code in Jupyter notebook renderers such as ipyvega.
// We're not fully supporting ipyvega yet, but this ensures the scripts will not fall over and will work with minimal effort on our part.
const context = {
outputs: [{
metadata: {}, data: {}
}],
};
// Required by JS code in Jupyter notebook renderers again, even scenepic (Microsoft Python widget) uses this.
const ele = document.getElementById("78a4cefb-af83-488c-8ab5-2152c172af23");
(function (element){
gotToUserScript = true;
element.setAttribute('style', 'white-space: pre;');console.log=function(text){element.textContent+=text+"\n"}
let age=42 //type annotations are not available in javascript you need to use typescript
//that is translated into javascript by a compiler
console.log("I am "+age+" old\n")
}).call(context, ele);
} catch (ex) {
console.error('VS Code Renderer failed to render output', ex);
if (gotToUserScript) {
throw ex;
} else {
// Something went wrong in our script that was generated by us.
element.setAttribute('style', 'white-space: pre;');console.log=function(text){element.textContent+=text+"\n"}
let age=42 //type annotations are not available in javascript you need to use typescript
//that is translated into javascript by a compiler
console.log("I am "+age+" old\n")
}
}
})();I am 42 old
Expected output:
I am 42 old
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reviewing pull request #245 and the notebook renderer entry point responsible for JavaScript magic output. Reproduce the example from the issue, compare the rendered result with the expected output, and verify that only “I am 42 old” remains visible.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, typescript
- Domain
- frontend, web-dev
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100