Skip to content

Commit

Permalink
add mermaidjs to markdown notebook ui tests
Browse files Browse the repository at this point in the history
  • Loading branch information
bollwyvl committed Mar 1, 2023
1 parent a30efbc commit 9f69978
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 2 deletions.
14 changes: 14 additions & 0 deletions galata/test/jupyterlab/notebook-markdown.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,4 +75,18 @@ test.describe('Notebook Markdown', () => {
imageName
);
});

test('Render a MermaidJS flowchart', async ({ page, tmpPath }) => {
await page.notebook.openByPath(`${tmpPath}/${fileName}`);
const imageName = 'render-mermaid-flowchart.png';
const cell = await page.notebook.getCell(3);
expect(await cell.screenshot()).toMatchSnapshot(imageName);
});

test('Render a MermaidJS error', async ({ page, tmpPath }) => {
await page.notebook.openByPath(`${tmpPath}/${fileName}`);
const imageName = 'render-mermaid-error.png';
const cell = await page.notebook.getCell(4);
expect(await cell.screenshot()).toMatchSnapshot(imageName);
});
});
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
30 changes: 29 additions & 1 deletion galata/test/jupyterlab/notebooks/markdown_notebook.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,34 @@
"$ ls\n",
"```"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Demonstration of MermaidJS\n",
"\n",
"Below is a diagram of a chicken and an egg.\n",
"\n",
"```mermaid\n",
"flowchart LR\n",
" chicken --> egg --> chicken\n",
"```"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Broken MermaidJS\n",
"\n",
"Below is a broken diagram.\n",
"\n",
"```mermaid\n",
"flowchart LR\n",
" chicken --> egg --> \n",
"```"
]
}
],
"metadata": {
Expand All @@ -95,7 +123,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.3"
"version": "3.11.0"
}
},
"nbformat": 4,
Expand Down
1 change: 1 addition & 0 deletions packages/markedparser-extension/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
},
"files": [
"lib/**/*.{d.ts,eot,gif,html,jpg,js,js.map,json,png,svg,woff2,ttf}",
"style/base.css",
"style/index.css",
"style/index.js",
"src/**/*.{ts,tsx}"
Expand Down
2 changes: 1 addition & 1 deletion packages/markedparser-extension/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ namespace Private {
document.body.appendChild(el);

try {
const { svg } = await _mermaid.mermaidAPI.render(id, token.text, el);
const { svg } = await _mermaid.render(id, token.text, el);
html = `<img src="data:image/svg+xml,${encodeURIComponent(svg)}" />`;
} catch (err) {
className = `${className} ${ERROR_CLASS}`;
Expand Down

0 comments on commit 9f69978

Please sign in to comment.