Skip to content

Commit

Permalink
Add support for markdown notebook renderers (microsoft#115191)
Browse files Browse the repository at this point in the history
* Use shared webpack version instead of installing locally for simple-browser

* Use npm for building markdown preview

* render markdown in webview.

* update markdown preview height and offset

* Add basic custom notebook renderer point

* update css

* style update.

* update markdown header padding left

* Add example of loading katex to extend the markdown-it renderer

* Rename global to make clear it only applies to markdown-in

* hide/remove markdown preview

* Add wait for initial markdown preview rendering before showing notebook

* Add double click to switch to editing mode

* Fix markdown cells not getting updated after editing

* style polish

* notebook.experimental.useMarkdownRenderer

* switch render strategy.

* Adding very intial drag drop support for notebook markdown cells

* Implement drag/drop stubs for test classes

* Revert unrelated file changes

* Move markdown notebook math to own extension

* Add missing imports

Co-authored-by: rebornix <penn.lv@gmail.com>
  • Loading branch information
mjbvz and rebornix authored Feb 11, 2021
1 parent c36a099 commit 35f8557
Show file tree
Hide file tree
Showing 31 changed files with 2,433 additions and 67 deletions.
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,6 @@
**/extensions/**/out/**
**/extensions/**/build/**
**/extensions/markdown-language-features/media/**
**/extensions/markdown-language-features/notebook-out/**
**/extensions/typescript-basics/test/colorize-fixtures/**
**/extensions/**/dist/**
2 changes: 2 additions & 0 deletions build/filters.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ module.exports.indentationFilter = [
'!**/*.Dockerfile',
'!**/*.dockerfile',
'!extensions/markdown-language-features/media/*.js',
'!extensions/markdown-language-features/notebook-out/*.js',
'!extensions/markdown-notebook-math/notebook-out/*.js',
'!extensions/simple-browser/media/*.js',
];

Expand Down
1 change: 1 addition & 0 deletions build/npm/dirs.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ exports.dirs = [
'extensions/json-language-features',
'extensions/json-language-features/server',
'extensions/markdown-language-features',
'extensions/markdown-notebook-math',
'extensions/merge-conflict',
'extensions/microsoft-authentication',
'extensions/npm',
Expand Down
964 changes: 964 additions & 0 deletions extensions/markdown-language-features/notebook-out/index.js

Large diffs are not rendered by default.

29 changes: 29 additions & 0 deletions extensions/markdown-language-features/notebook/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/

import * as MarkdownIt from 'markdown-it';

declare const acquireNotebookRendererApi: any;
type extendMarkdownItFnType = (
(f: (md: MarkdownIt.MarkdownIt) => void) => void
);

(function () {
const markdownIt = new MarkdownIt();

(globalThis as any).extendMarkdownIt = ((f: (md: MarkdownIt.MarkdownIt) => void) => {
f(markdownIt);
}) as extendMarkdownItFnType;

const notebook = acquireNotebookRendererApi('notebookCoreTestRenderer');

notebook.onDidCreateMarkdown(({ element, content }: any) => {
console.log('did create markdown cell');
const rendered = markdownIt.render(content);
element.innerHTML = rendered;
});

console.log('markdown-it');
}());
7 changes: 7 additions & 0 deletions extensions/markdown-language-features/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,13 @@
"onCustomEditor:vscode.markdown.preview.editor"
],
"contributes": {
"notebookMarkdownRenderer": [
{
"id": "markdownItRenderer",
"displayName": "Markdown it renderer",
"entrypoint": "./notebook-out/index.js"
}
],
"commands": [
{
"command": "markdown.showPreview",
Expand Down
27 changes: 27 additions & 0 deletions extensions/markdown-language-features/webpack.notebook.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
const path = require('path');

module.exports = {
entry: {
index: './notebook/index.ts'
},
module: {
rules: [
{
test: /\.tsx?$/,
use: 'ts-loader',
exclude: /node_modules/
}
]
},
resolve: {
extensions: ['.tsx', '.ts', '.js']
},
output: {
filename: '[name].js',
path: path.resolve(__dirname, 'notebook-out')
}
};
12 changes: 12 additions & 0 deletions extensions/markdown-notebook-math/.vscodeignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
test/**
test-workspace/**
src/**
tsconfig.json
out/test/**
out/**
extension.webpack.config.js
extension-browser.webpack.config.js
cgmanifest.json
yarn.lock
preview-src/**
webpack.config.js
3 changes: 3 additions & 0 deletions extensions/markdown-notebook-math/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Markdown Notebook Math support

**Notice:** This extension is bundled with Visual Studio Code. It can be disabled but not uninstalled.
Binary file added extensions/markdown-notebook-math/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

Large diffs are not rendered by default.

22 changes: 22 additions & 0 deletions extensions/markdown-notebook-math/notebook/extension.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import type * as markdownIt from 'markdown-it';

import 'katex/dist/katex.min.css';

declare const extendMarkdownIt: undefined | (
(f: (md: markdownIt.MarkdownIt) => void) => void
);

(function () {
const katex = require('@iktakahiro/markdown-it-katex');

if (typeof extendMarkdownIt !== 'undefined') {
extendMarkdownIt((md: markdownIt.MarkdownIt) => {
md.use(katex);
});
}
}());

12 changes: 12 additions & 0 deletions extensions/markdown-notebook-math/notebook/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"extends": "../../shared.tsconfig.json",
"compilerOptions": {
"outDir": "./dist/",
"jsx": "react",
"lib": [
"es2018",
"DOM",
"DOM.Iterable"
]
}
}
45 changes: 45 additions & 0 deletions extensions/markdown-notebook-math/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
{
"name": "markdown-notebook-math",
"displayName": "%displayName%",
"description": "%description%",
"version": "1.0.0",
"icon": "icon.png",
"publisher": "vscode",
"enableProposedApi": true,
"license": "MIT",
"aiKey": "AIF-d9b70cd4-b9f9-4d70-929b-a071c400b217",
"engines": {
"vscode": "^1.54.0"
},
"categories": [
"Other"
],
"contributes": {
"notebookMarkdownRenderer": [
{
"id": "markdownItRenderer-katex",
"displayName": "Markdown it renderer",
"entrypoint": "./notebook-out/extension.js"
}
]
},
"scripts": {
"compile": "npm run build-notebook",
"watch": "npm run build-notebook",
"build-notebook": "npx webpack-cli --config webpack.notebook.js --mode production"
},
"dependencies": {
"@iktakahiro/markdown-it-katex": "^4.0.1"
},
"devDependencies": {
"@types/markdown-it": "^0.0.0",
"css-loader": "^5.0.2",
"markdown-it": "^12.0.4",
"style-loader": "^2.0.0",
"url-loader": "^4.1.1"
},
"repository": {
"type": "git",
"url": "https://github.com/microsoft/vscode.git"
}
}
4 changes: 4 additions & 0 deletions extensions/markdown-notebook-math/package.nls.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"displayName": "Markdown Notebook math",
"description": "Provides rich language support for Markdown."
}
35 changes: 35 additions & 0 deletions extensions/markdown-notebook-math/webpack.notebook.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
const path = require('path');

module.exports = {
entry: {
extension: './notebook/extension.ts',
},
module: {
rules: [
{
test: /\.tsx?$/,
use: 'ts-loader',
exclude: /node_modules/
},
{
test: /\.css$/i,
use: ['style-loader', 'css-loader'],
},
{
test: /\.(woff|woff2|eot|ttf|otf)$/i,
use: ['url-loader?limit=100000']
},
],
},
resolve: {
extensions: ['.tsx', '.ts', '.js']
},
output: {
filename: '[name].js',
path: path.resolve(__dirname, 'notebook-out')
}
};
Loading

0 comments on commit 35f8557

Please sign in to comment.