Skip to content

Commit

Permalink
compliance with "prettier"
Browse files Browse the repository at this point in the history
  • Loading branch information
tavin committed Mar 26, 2023
1 parent 38270d4 commit c53884a
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 20 deletions.
11 changes: 6 additions & 5 deletions src/MySTContentFactory.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
import { MarkdownCell } from '@jupyterlab/cells';
import { NotebookPanel, StaticNotebook } from '@jupyterlab/notebook';
import { MySTMarkdownCell } from './MySTMarkdownCell';
import { MySTOptionsProvider, MySTNotebookDefaults } from './myst';
import { MySTNotebookOptions, MySTNotebookDefaults } from './myst';

export class MySTContentFactory extends NotebookPanel.ContentFactory {
mystOptions: MySTNotebookOptions;

mystOptions: MySTOptionsProvider<StaticNotebook>;

constructor(options = {},
mystOptions = new MySTNotebookDefaults() as MySTOptionsProvider<StaticNotebook>) {
constructor(
options = {},
mystOptions = new MySTNotebookDefaults() as MySTNotebookOptions
) {
super(options);
this.mystOptions = mystOptions;
}
Expand Down
14 changes: 10 additions & 4 deletions src/MySTMarkdownCell.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {
} from '@myst-theme/providers';
import { render } from 'react-dom';
import { useParse } from 'myst-to-react';
import { parseContent, MySTOptionsProvider } from './myst';
import { parseContent, MySTNotebookOptions } from './myst';
import { IMySTMarkdownCell } from './types';
import { linkFactory } from './links';
import { selectAll } from 'unist-util-select';
Expand All @@ -31,15 +31,18 @@ export class MySTMarkdownCell
private _doneRendering = new PromiseDelegate<void>();
private _doRendering = false;

mystOptions: MySTOptionsProvider<StaticNotebook>;
mystOptions: MySTNotebookOptions;

myst: {
pre?: GenericParent;
post?: GenericParent;
node?: HTMLDivElement;
} = {};

constructor(options: MarkdownCell.IOptions, mystOptions: MySTOptionsProvider<StaticNotebook>) {
constructor(
options: MarkdownCell.IOptions,
mystOptions: MySTNotebookOptions
) {
super(options);
this.mystOptions = mystOptions;

Expand Down Expand Up @@ -67,7 +70,10 @@ export class MySTMarkdownCell
this._doneRendering = new PromiseDelegate<void>();
const notebook = this.parent as StaticNotebook;
this.myst.pre = undefined;
const parseComplete = parseContent(notebook, this.mystOptions.get(notebook));
const parseComplete = parseContent(
notebook,
this.mystOptions.get(notebook)
);
const widget = new Widget({ node: this.myst.node });
widget.addClass('myst');
widget.addClass('jp-MarkdownOutput');
Expand Down
15 changes: 10 additions & 5 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,10 @@ import {
NotebookPanel,
NotebookWidgetFactory,
NotebookActions,
Notebook,
StaticNotebook
Notebook
} from '@jupyterlab/notebook';
import { Cell } from '@jupyterlab/cells';
import { MySTOptionsProvider } from './myst';
import { MySTNotebookOptions } from './myst';
import { MySTContentFactory } from './MySTContentFactory';

import { ISessionContextDialogs } from '@jupyterlab/apputils';
Expand All @@ -37,7 +36,9 @@ const mystIcon = new LabIcon({
* Extension point for MyST options to be defined given a notebook.
* A null provider results in default parser options appropriate to all notebooks.
*/
export const IMySTNotebookOptions = new Token<MySTOptionsProvider<StaticNotebook>>('jupyterlab-myst:IMySTNotebookOptions');
export const IMySTNotebookOptions = new Token<MySTNotebookOptions>(
'jupyterlab-myst:IMySTNotebookOptions'
);

/**
* The notebook content factory provider.
Expand All @@ -48,7 +49,11 @@ const plugin: JupyterFrontEndPlugin<NotebookPanel.IContentFactory> = {
requires: [IEditorServices],
optional: [IMySTNotebookOptions],
autoStart: true,
activate: (app: JupyterFrontEnd, editorServices: IEditorServices, mystOptions: MySTOptionsProvider<StaticNotebook>) => {
activate: (
app: JupyterFrontEnd,
editorServices: IEditorServices,
mystOptions: MySTNotebookOptions
) => {
console.log('JupyterLab extension jupyterlab-myst is activated!');
const editorFactory = editorServices.factoryService.newInlineEditor;
return new MySTContentFactory({ editorFactory }, mystOptions || undefined);
Expand Down
20 changes: 14 additions & 6 deletions src/myst.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,23 +37,28 @@ import { internalLinksPlugin } from './links';
import { addCiteChildrenPlugin } from './citations';

export interface MySTOptions {

parserOptions: Partial<AllOptions>;
}

export interface MySTOptionsProvider<Widget> {

get(widget: Widget): MySTOptions;
}

export class MySTNotebookDefaults implements MySTOptionsProvider<StaticNotebook> {
/**
* The interface which must be implemented to customize options for notebooks.
*/
export type MySTNotebookOptions = MySTOptionsProvider<StaticNotebook>;

/**
* Global default myst options for notebooks.
*/
export class MySTNotebookDefaults implements MySTNotebookOptions {
get(notebook: StaticNotebook): MySTOptions {
return {
parserOptions: {
directives: [cardDirective, gridDirective, ...tabDirectives],
roles: [evalRole],
},
roles: [evalRole]
}
};
}
}
Expand All @@ -70,7 +75,10 @@ const evalRole: RoleSpec = {
}
};

export function markdownParse(text: string, options: Partial<AllOptions>): Root {
export function markdownParse(
text: string,
options: Partial<AllOptions>
): Root {
const mdast = mystParse(text, options);
// Parsing individually here requires that link and footnote references are contained to the cell
// This is consistent with the current Jupyter markdown renderer
Expand Down

0 comments on commit c53884a

Please sign in to comment.