Skip to content

Commit

Permalink
Merge pull request #137 from conwnet/feat/fix-extension
Browse files Browse the repository at this point in the history
fix: the authority change break jupyter-web extension
  • Loading branch information
conwnet authored Feb 16, 2021
2 parents b3a07e1 + 1e10326 commit 8be34fd
Show file tree
Hide file tree
Showing 6 changed files with 1,065 additions and 1,514 deletions.
36 changes: 0 additions & 36 deletions extensions/jupyter-web/extension.webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,49 +19,13 @@ module.exports = /** @type WebpackConfig */ {
extension: "./src/extension.js",
},
resolve: {
// node: { fs: 'empty', child_process: 'empty', net: 'empty', tls: 'empty' },
fallback: {
fs: false,
child_process: false,
net: false,
tls: false,
stream: false,
assert: false,
url: false,
buffer: false,
querystring: false,
zlib: false,
os: false,
crypto: require.resolve("crypto-browserify"),
},
mainFields: ["module", "main"],
extensions: [".ts", ".js"], // support ts-files and js-files
alias: {
https: "https-browserify",
http: "http-browserify",
},
},
module: {
rules: [
{
test: /\.ts$/,
exclude: /node_modules/,
use: [
{
// configure TypeScript loader:
// * enable sources maps for end-to-end source maps
loader: "ts-loader",
options: {
compilerOptions: {
sourceMap: true,
declaration: false,
},
},
},
],
},
],
},
externals: {
vscode: "commonjs vscode", // ignored because it doesn't exist
},
Expand Down
14 changes: 0 additions & 14 deletions extensions/jupyter-web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -99,23 +99,9 @@
"dev": "webpack --config extension.webpack.config.js --watch"
},
"devDependencies": {
"@types/mocha": "^2.2.42",
"@types/node": "^7.0.43",
"@types/vscode": "^1.52.0",
"eslint": "^4.6.1",
"typescript": "^2.6.1",
"webpack": "^5.21.2",
"webpack-cli": "^4.5.0"
},
"dependencies": {
"cheerio": "^1.0.0-rc.2",
"crypto-browserify": "^3.12.0",
"global-jsdom": "^8.0.0-beta.1",
"http-browserify": "^1.7.0",
"https-browserify": "^1.0.0",
"jsdom": "^11.5.1",
"node-prismjs": "^0.1.1",
"path": "^0.12.7",
"prismjs": "^1.9.0"
}
}
50 changes: 21 additions & 29 deletions extensions/jupyter-web/src/extension.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,12 @@
import vscode from "vscode";

export const parseUri = (uri) => {
const [owner, repo, branch] = (uri.authority || "")
.split("+")
.filter(Boolean);
return {
owner,
repo,
branch,
path: uri.path,
};
};

vscode.commands.registerCommand("jupyter.showPreview", async function (uri) {
try {
const { owner, repo, branch, path } = parseUri(uri);
const authority = await vscode.commands.executeCommand('github1s.get-current-authority');
// TODO: It may not work fine when there are special characters in `ref` or `path`
const [owner, repo, ref] = (authority || "").split('+').filter(Boolean);
const path = uri.path;

// const success = await vscode.commands.executeCommand('vscode.previewHtml', previewUri, vscode.ViewColumn.Two, 'IPython Notebook Preview');
// Create and show panel
const panel = vscode.window.createWebviewPanel(
Expand All @@ -24,23 +16,23 @@ vscode.commands.registerCommand("jupyter.showPreview", async function (uri) {
{ enableScripts: true, retainContextWhenHidden: true }
);
panel.webview.html = `
<style>
.vscode-dark {
padding: 0px !important;
}
#menubar {
display : none !important;
}
.nbviewer {
padding-top: 0px !important ;
}
<style>
.vscode-dark {
padding: 0px !important;
}
#menubar {
display : none !important;
}
.nbviewer {
padding-top: 0px !important ;
}
</style>
<iframe
class="ifrm"
style="height: 100vh; width: 100vw; padding: 0px;"
class="webview ready"
sandbox="allow-scripts allow-same-origin allow-forms allow-pointer-lock allow-downloads"
src="https://nbviewer.jupyter.org/github/${owner}/${repo}/blob/${branch}${path}"
<iframe
class="ifrm"
style="height: 100vh; width: 100vw; padding: 0px;"
class="webview ready"
sandbox="allow-scripts allow-same-origin allow-forms allow-pointer-lock allow-downloads"
src="https://nbviewer.jupyter.org/github/${owner}/${repo}/blob/${ref}${path}"
>
</iframe>
`;
Expand Down
Loading

0 comments on commit 8be34fd

Please sign in to comment.