Skip to content

Commit

Permalink
ENH: update theme (#215)
Browse files Browse the repository at this point in the history
* MAINT: bump dependencies

* FIX: bugs in CI

* MAINT: run prettier

* FIX: restore test file

* fix: enable frontmatter in viewer by default

* fix: don't pass unused options

* TEST: update tests to include markdown viewer

* MAINT: run linter
  • Loading branch information
agoose77 authored Feb 15, 2024
1 parent b4c5d2c commit b0191ba
Show file tree
Hide file tree
Showing 20 changed files with 156 additions and 92 deletions.
8 changes: 5 additions & 3 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@ name: Build

on:
push:
branches: main
branches:
- main
pull_request:
branches: '*'
branches:
- '*'

concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
Expand Down Expand Up @@ -159,4 +161,4 @@ jobs:
- uses: jupyterlab/maintainer-tools/.github/actions/base-setup@v1
- uses: jupyterlab/maintainer-tools/.github/actions/check-links@v1
with:
ignore_links: "https?://mybinder\.org.*"
ignore_links: "https?://mybinder\\.org.*"
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,9 @@
"@jupyterlab/notebook": "^4.0.0",
"@jupyterlab/rendermime": "^4.0.0",
"@jupyterlab/translation": "^4.0.0",
"@myst-theme/diagrams": "^0.5.21",
"@myst-theme/frontmatter": "^0.5.21",
"@myst-theme/providers": "^0.5.21",
"@myst-theme/diagrams": "^0.5.22",
"@myst-theme/frontmatter": "^0.5.22",
"@myst-theme/providers": "^0.5.22",
"katex": "^0.15.2",
"myst-common": "^1.1.24",
"myst-ext-card": "^1.0.5",
Expand Down
9 changes: 9 additions & 0 deletions src/__tests__/jupyterlab_myst.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/**
* Example of [Jest](https://jestjs.io/docs/getting-started) unit tests
*/

describe('jupyterlab-myst', () => {
it('should be tested', () => {
expect(1 + 1).toEqual(2);
});
});
16 changes: 6 additions & 10 deletions src/components/listItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,10 @@ export function ListItem({
line,
children
}: {
checked?: boolean,
line?: number,
children?: any[]

}): JSX.Element {
checked?: boolean;
line?: number;
children?: any[];
}): JSX.Element {
if (checked === null) {
return (
<li>
Expand All @@ -54,11 +53,8 @@ export function ListItem({
);
}
return (
<TaskItem
checked={checked}
line={line}
>
<TaskItem checked={checked} line={line}>
<MyST ast={children} />
</TaskItem>
);
};
}
17 changes: 14 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
import { Cell } from '@jupyterlab/cells';
import { MySTContentFactory } from './MySTContentFactory';
import { IRenderMimeRegistry } from '@jupyterlab/rendermime';

import { ISettingRegistry } from '@jupyterlab/settingregistry';
import { notebookCellExecuted } from './actions';
import { mystMarkdownRendererFactory } from './mime';

Expand Down Expand Up @@ -59,15 +59,26 @@ const mimeRendererPlugin: JupyterFrontEndPlugin<void> = {
id: 'jupyterlab-myst:mime-renderer',
requires: [IRenderMimeRegistry],
autoStart: true,
optional: [IMarkdownViewerTracker],
optional: [IMarkdownViewerTracker, ISettingRegistry],
activate: (
app: JupyterFrontEnd,
registry: IRenderMimeRegistry,
// We don't need this tracker directly, but it ensures that the built-in
// Markdown renderer is registered, so that we can then safely add our own.
tracker?: IMarkdownViewerTracker
tracker?: IMarkdownViewerTracker,
settingRegistry?: ISettingRegistry
) => {
console.log('Using jupyterlab-myst:mime-renderer');

// Enable frontmatter by default
if (settingRegistry) {
settingRegistry
.load('@jupyterlab/markdownviewer-extension:plugin')
.then((settings: ISettingRegistry.ISettings) => {
settings.set('hideFrontMatter', false);
});
}

// Add the MyST markdown renderer factory.
registry.addFactory(mystMarkdownRendererFactory);
}
Expand Down
21 changes: 10 additions & 11 deletions src/myst.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,11 @@ import { exerciseDirectives } from 'myst-ext-exercise';
import { StaticNotebook } from '@jupyterlab/notebook';
import { IRenderMimeRegistry } from '@jupyterlab/rendermime';
import { IRenderMime } from '@jupyterlab/rendermime-interfaces';
import { imageUrlSourceTransform, internalLinksTransform, addCiteChildrenPlugin } from './transforms';
import {
imageUrlSourceTransform,
internalLinksTransform,
addCiteChildrenPlugin
} from './transforms';
import { IUserExpressionMetadata } from './userExpressions';
import { IMySTMarkdownCell } from './types';
import { Cell, ICellModel } from '@jupyterlab/cells';
Expand Down Expand Up @@ -92,16 +96,14 @@ export async function processArticleMDAST(
article: mdast as any
};

const { frontmatter: frontmatterRaw } = getFrontmatter(file, mdast, {
});
const { frontmatter: frontmatterRaw } = getFrontmatter(file, mdast);
// unnestKernelSpec(rawPageFrontmatter);
const frontmatter = validatePageFrontmatter(frontmatterRaw, {
property: 'frontmatter',
messages: {}
});

const state = new ReferenceState(
"<PATH>",
{
const state = new ReferenceState('<PATH>', {
numbering: frontmatter.numbering,
vfile: file
});
Expand Down Expand Up @@ -158,17 +160,15 @@ export async function processNotebookMDAST(
const { frontmatter: frontmatterRaw } = getFrontmatter(
file,
// This is the first cell, which might have a YAML block or header.
mdast.children[0] as any,
{
}
mdast.children[0] as any
);

const frontmatter = validatePageFrontmatter(frontmatterRaw, {
property: 'frontmatter',
messages: {}
});

const state = new ReferenceState("<PATH>",{
const state = new ReferenceState('<PATH>', {
numbering: frontmatter.numbering,
vfile: file
});
Expand Down Expand Up @@ -226,7 +226,6 @@ export async function renderNotebook(notebook: StaticNotebook) {
frontmatter,
mdast: processedMDAST
} = await processNotebookMDAST(

mdast,
notebook.rendermime.resolver ?? undefined
);
Expand Down
10 changes: 8 additions & 2 deletions src/renderers.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React from 'react';
import { DEFAULT_RENDERERS } from 'myst-to-react';
import { MermaidNodeRenderer } from '@myst-theme/diagrams';
import { NodeRenderer } from '@myst-theme/providers';
import { InlineExpression, ListItem } from './components';
import { InlineExpression, ListItem } from './components';
import { useSanitizer } from './providers';

export const renderers: Record<string, NodeRenderer> = {
Expand All @@ -12,7 +12,13 @@ export const renderers: Record<string, NodeRenderer> = {
return <InlineExpression value={node.value} />;
},
listItem: ({ node }) => {
return <ListItem checked={node.checked} line={node.position?.start.line} children={node.children}/>;
return (
<ListItem
checked={node.checked}
line={node.position?.start.line}
children={node.children}
/>
);
},
html: ({ node }, children) => {
const { sanitizer } = useSanitizer();
Expand Down
1 change: 0 additions & 1 deletion src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { MarkdownCell } from '@jupyterlab/cells';
import { IMySTModel } from './widget';
import { IRenderMime } from '@jupyterlab/rendermime-interfaces';


export type IMySTMarkdownCell = MarkdownCell & {
readonly fragmentMDAST: any | undefined;
readonly attachmentsResolver: IRenderMime.IResolver;
Expand Down
3 changes: 0 additions & 3 deletions src/userExpressions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { PartialJSONObject } from '@lumino/coreutils';
import { Cell } from '@jupyterlab/cells';
import type { IMySTMarkdownCell } from './types';


export const metadataSection = 'user_expressions';

/**
Expand Down Expand Up @@ -38,7 +37,6 @@ export function isError(output: IExpressionResult): output is IExpressionError {
return output.status === 'error';
}


export interface IUserExpressionMetadata extends PartialJSONObject {
expression: string;
result: IExpressionResult;
Expand All @@ -48,7 +46,6 @@ export interface IUserExpressionsMetadata extends PartialJSONObject {
[metadataSection]: IUserExpressionMetadata[];
}


export function getUserExpressions(
cell: IMySTMarkdownCell | Cell
): IUserExpressionMetadata[] | undefined {
Expand Down
7 changes: 4 additions & 3 deletions src/widget.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,13 @@ import {
} from '@myst-theme/providers';
import { MyST } from 'myst-to-react';
import React from 'react';
import { UserExpressionsProvider,
import {
UserExpressionsProvider,
ITaskItemChange,
ITaskItemController,
TaskItemControllerProvider,
SanitizerProvider } from './providers';
SanitizerProvider
} from './providers';
import { renderers } from './renderers';
import { IUserExpressionMetadata } from './userExpressions';
import { linkFactory } from './transforms';
Expand Down Expand Up @@ -122,7 +124,6 @@ export class MySTWidget extends VDomRenderer<IMySTModel> {
this._sanitizer = sanitizer;
this._taskItemController = change => this._taskItemChanged.emit(change);
this.addClass('myst');

}

private _trusted?: boolean = false;
Expand Down
2 changes: 2 additions & 0 deletions ui-tests/jupyter_server_test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,5 @@

# Uncomment to set server log level to debug level
# c.ServerApp.log_level = "DEBUG"

c.ServerApp.port = 9999
26 changes: 13 additions & 13 deletions ui-tests/package.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
{
"name": "jupyterlab-myst-ui-tests",
"version": "1.0.0",
"description": "JupyterLab jupyterlab-myst Integration Tests",
"private": true,
"scripts": {
"start": "jupyter lab --config jupyter_server_test_config.py",
"test": "jlpm playwright test",
"test:update": "jlpm playwright test --update-snapshots"
},
"devDependencies": {
"@jupyterlab/galata": "^5.0.5",
"@playwright/test": "^1.37.0"
}
"name": "jupyterlab-myst-ui-tests",
"version": "1.0.0",
"description": "JupyterLab jupyterlab-myst Integration Tests",
"private": true,
"scripts": {
"start": "jupyter lab --config jupyter_server_test_config.py",
"test": "jlpm playwright test",
"test:update": "jlpm playwright test --update-snapshots"
},
"devDependencies": {
"@jupyterlab/galata": "^5.0.5",
"@playwright/test": "^1.37.0"
}
}
6 changes: 5 additions & 1 deletion ui-tests/playwright.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,13 @@ const baseConfig = require('@jupyterlab/galata/lib/playwright-config');

module.exports = {
...baseConfig,
use: {
...baseConfig.use,
baseURL: process.env.TARGET_URL ?? 'http://127.0.0.1:9999'
},
webServer: {
command: 'jlpm start',
url: 'http://localhost:8888/lab',
url: 'http://localhost:9999/lab',
timeout: 120 * 1000,
reuseExistingServer: !process.env.CI
}
Expand Down
31 changes: 31 additions & 0 deletions ui-tests/tests/files-run.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// Copyright (c) Jupyter Development Team.
// Distributed under the terms of the Modified BSD License.

import { expect, galata, test } from '@jupyterlab/galata';
import * as path from 'path';

const fileName = 'myst_tests.md';
const FACTORY = 'Markdown Preview';
// test.use({ tmpPath: 'notebook-run-test' });

test.describe.serial('File Run', () => {
test.beforeEach(async ({ request, page, tmpPath }) => {
const contents = galata.newContentsHelper(request, page);
await contents.uploadFile(
path.resolve(__dirname, `./files/${fileName}`),
`${tmpPath}/${fileName}`
);
});

test('View Markdown file and render result', async ({ page, tmpPath }) => {
const filePath = `${tmpPath}/${fileName}`;
await page.filebrowser.open(filePath, FACTORY);

const name = path.basename(filePath);
await page.activity.getTab(name);

const panel = await page.activity.getPanel(name);

expect(await panel!.screenshot()).toMatchSnapshot();
});
});
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 6 additions & 0 deletions ui-tests/tests/files/myst_tests.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Hello

```{note}
:class: dropdown
This is MyST in a notebook rendered by `jupyterlab-myst`!!
```
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 5 additions & 4 deletions ui-tests/tests/notebooks/myst_tests.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -7,26 +7,27 @@
"tags": []
},
"source": [
"## Hello\n",
"# Hello\n",
"\n",
"```{note}\n",
":class: dropdown\n",
"\n",
"This is MyST in a notebook rendered by `jupyterlab-myst`!!\n",
"```"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "124203ea-d9d8-4c2b-91b7-eca7cd68ee3f",
"id": "f3cc605e-a90d-4b26-9771-8f7a27b58134",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3.9.10 64-bit",
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
Expand All @@ -40,7 +41,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.10"
"version": "3.10.13"
},
"vscode": {
"interpreter": {
Expand Down
Loading

0 comments on commit b0191ba

Please sign in to comment.