Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MAINT: reorganise extension files #214

Merged
merged 7 commits into from
Feb 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,24 +69,24 @@
"@myst-theme/frontmatter": "^0.5.21",
"@myst-theme/providers": "^0.5.21",
"katex": "^0.15.2",
"myst-common": "^1.1.21",
"myst-common": "^1.1.24",
"myst-ext-card": "^1.0.5",
"myst-ext-exercise": "^1.0.5",
"myst-ext-grid": "^1.0.5",
"myst-ext-proof": "^1.0.7",
"myst-ext-proof": "^1.0.8",
"myst-ext-tabs": "^1.0.5",
"myst-frontmatter": "^1.1.21",
"myst-parser": "^1.0.21",
"myst-to-html": "^1.0.21",
"myst-frontmatter": "^1.1.24",
"myst-parser": "^1.0.22",
"myst-to-html": "^1.0.22",
"myst-to-react": "^0.5.21",
"myst-transforms": "^1.1.19"
"myst-transforms": "^1.2.1"
},
"devDependencies": {
"@babel/core": "^7.0.0",
"@babel/preset-env": "^7.0.0",
"@jupyterlab/builder": "^4.0.0",
"@jupyterlab/testutils": "^4.0.0",
"@myst-theme/styles": "^0.3.3",
"@myst-theme/styles": "^0.5.21",
"@tailwindcss/typography": "^0.5.8",
"@types/jest": "^29.2.0",
"@types/json-schema": "^7.0.11",
Expand Down
4 changes: 2 additions & 2 deletions src/MySTMarkdownCell.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ import { ActivityMonitor } from '@jupyterlab/coreutils';
import { AttachmentsResolver } from '@jupyterlab/attachments';
import { IMapChange } from '@jupyter/ydoc';
import { IMySTMarkdownCell } from './types';
import { getUserExpressions, metadataSection } from './metadata';
import { getUserExpressions, metadataSection } from './userExpressions';
import { IMySTModel, MySTModel, MySTWidget } from './widget';
import { markdownParse, processCellMDAST, renderNotebook } from './myst';
import { IRenderMime } from '@jupyterlab/rendermime-interfaces';
import { ITaskItemChange } from './TaskItemControllerProvider';
import { ITaskItemChange } from './providers';

class IMySTWidget {}

Expand Down
9 changes: 0 additions & 9 deletions src/__tests__/jupyterlab_myst.spec.ts

This file was deleted.

2 changes: 1 addition & 1 deletion src/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
getUserExpressions,
setUserExpressions,
deleteUserExpressions
} from './metadata';
} from './userExpressions';
import {
INotebookTracker,
Notebook,
Expand Down
2 changes: 2 additions & 0 deletions src/components/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from './inlineExpression';
export * from './listItem';
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import React, { useEffect, useRef, useState } from 'react';
import { useUserExpressions } from './UserExpressionsProvider';
import { useUserExpressions } from '../providers';
import { SingletonLayout, Widget } from '@lumino/widgets';
import { IRenderMimeRegistry } from '@jupyterlab/rendermime';
import {
IUserExpressionMetadata,
IExpressionError,
IExpressionResult,
isError,
isOutput
} from './userExpressions';
import { IUserExpressionMetadata } from './metadata';
} from '../userExpressions';

export interface IRenderedExpressionOptions {
expression: string;
Expand Down Expand Up @@ -213,7 +213,7 @@ function MIMEBundleRenderer({
return <div ref={ref} className="not-prose inline-block" />;
}

export function InlineRenderer({ value }: { value?: string }): JSX.Element {
export function InlineExpression({ value }: { value?: string }): JSX.Element {
const { expressions, rendermime, trusted } = useUserExpressions();

if (!expressions || !rendermime) {
Expand Down
32 changes: 18 additions & 14 deletions src/taskItem.tsx → src/components/listItem.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import React from 'react';
import { NodeRenderer } from '@myst-theme/providers';
import type { ListItem } from 'myst-spec-ext';
import { useTaskItemController } from './TaskItemControllerProvider';
import { useTaskItemController } from '../providers';
import { MyST } from 'myst-to-react';

function TaskItem({
Expand All @@ -10,7 +8,7 @@ function TaskItem({
children
}: {
checked?: boolean;
children: React.ReactNode;
children?: React.ReactNode;
line?: number;
}) {
// The rendering waiting on promises from Jupyter is slow
Expand Down Expand Up @@ -38,23 +36,29 @@ function TaskItem({
);
}

export const listItem: NodeRenderer<ListItem & { checked?: boolean }> = ({
node
}) => {
if (node.checked === null) {
export function ListItem({
checked,
line,
children
}: {
checked?: boolean,
line?: number,
children?: any[]

}): JSX.Element {
if (checked === null) {
return (
<li key={node.key}>
<MyST ast={node.children} />
<li>
<MyST ast={children} />
</li>
);
}
return (
<TaskItem
key={node.key}
checked={node.checked}
line={node.position?.start.line}
checked={checked}
line={line}
>
<MyST ast={node.children} />
<MyST ast={children} />
</TaskItem>
);
};
56 changes: 0 additions & 56 deletions src/metadata.ts

This file was deleted.

4 changes: 2 additions & 2 deletions src/mime.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ export class RenderedMySTMarkdown
extends MySTWidget
implements IRenderMime.IRenderer
{
readonly resolver: IRenderMime.IResolver | undefined;
readonly linkHandler: IRenderMime.ILinkHandler | undefined;
readonly resolver?: IRenderMime.IResolver;
readonly linkHandler?: IRenderMime.ILinkHandler;

constructor(options: IRenderMime.IRendererOptions) {
super({
Expand Down
28 changes: 12 additions & 16 deletions src/myst.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,8 @@ import { exerciseDirectives } from 'myst-ext-exercise';
import { StaticNotebook } from '@jupyterlab/notebook';
import { IRenderMimeRegistry } from '@jupyterlab/rendermime';
import { IRenderMime } from '@jupyterlab/rendermime-interfaces';
import { imageUrlSourceTransform } from './images';
import { internalLinksTransform } from './links';
import { addCiteChildrenPlugin } from './citations';
import { evalRole } from './roles';
import { IUserExpressionMetadata } from './metadata';
import { imageUrlSourceTransform, internalLinksTransform, addCiteChildrenPlugin } from './transforms';
import { IUserExpressionMetadata } from './userExpressions';
import { IMySTMarkdownCell } from './types';
import { Cell, ICellModel } from '@jupyterlab/cells';
import { MySTModel } from './widget';
Expand All @@ -60,7 +57,7 @@ export function markdownParse(text: string): Root {
...tabDirectives,
...exerciseDirectives
],
roles: [evalRole]
roles: []
});
};

Expand Down Expand Up @@ -96,21 +93,21 @@ export async function processArticleMDAST(
};

const { frontmatter: frontmatterRaw } = getFrontmatter(file, mdast, {
removeYaml: true,
removeHeading: true
});
const frontmatter = validatePageFrontmatter(frontmatterRaw, {
property: 'frontmatter',
messages: {}
});

const state = new ReferenceState({
const state = new ReferenceState(
"<PATH>",
{
numbering: frontmatter.numbering,
file
vfile: file
});
unified()
.use(mathPlugin, { macros: frontmatter?.math ?? {} }) // This must happen before enumeration, as it can add labels
.use(glossaryPlugin, { state }) // This should be before the enumerate plugins
.use(glossaryPlugin) // This should be before the enumerate plugins
.use(abbreviationPlugin, { abbreviations: frontmatter.abbreviations })
.use(enumerateTargetsPlugin, { state })
.use(linksPlugin, { transformers: linkTransforms })
Expand Down Expand Up @@ -163,8 +160,6 @@ export async function processNotebookMDAST(
// This is the first cell, which might have a YAML block or header.
mdast.children[0] as any,
{
removeYaml: true,
removeHeading: true
}
);

Expand All @@ -173,14 +168,14 @@ export async function processNotebookMDAST(
messages: {}
});

const state = new ReferenceState({
const state = new ReferenceState("<PATH>",{
numbering: frontmatter.numbering,
file
vfile: file
});

unified()
.use(mathPlugin, { macros: frontmatter?.math ?? {} }) // This must happen before enumeration, as it can add labels
.use(glossaryPlugin, { state }) // This should be before the enumerate plugins
.use(glossaryPlugin) // This should be before the enumerate plugins
.use(abbreviationPlugin, { abbreviations: frontmatter.abbreviations })
.use(enumerateTargetsPlugin, { state })
.use(linksPlugin, { transformers: linkTransforms })
Expand Down Expand Up @@ -231,6 +226,7 @@ export async function renderNotebook(notebook: StaticNotebook) {
frontmatter,
mdast: processedMDAST
} = await processNotebookMDAST(

mdast,
notebook.rendermime.resolver ?? undefined
);
Expand Down
3 changes: 3 additions & 0 deletions src/providers/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export * from './sanitizer';
export * from './taskItem';
export * from './userExpressions';
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, { createContext, useContext } from 'react';
import { IUserExpressionMetadata } from './metadata';
import { IUserExpressionMetadata } from '../userExpressions';
import { IRenderMimeRegistry } from '@jupyterlab/rendermime';

type UserExpressionsState = {
Expand Down
11 changes: 6 additions & 5 deletions src/renderers.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,18 @@ import React from 'react';
import { DEFAULT_RENDERERS } from 'myst-to-react';
import { MermaidNodeRenderer } from '@myst-theme/diagrams';
import { NodeRenderer } from '@myst-theme/providers';
import { InlineRenderer } from './inlineExpression';
import { listItem } from './taskItem';
import { useSanitizer } from './SanitizerProvider';
import { InlineExpression, ListItem } from './components';
import { useSanitizer } from './providers';

export const renderers: Record<string, NodeRenderer> = {
...DEFAULT_RENDERERS,
mermaid: MermaidNodeRenderer,
inlineExpression: ({ node }) => {
return <InlineRenderer value={node.value} />;
return <InlineExpression value={node.value} />;
},
listItem: ({ node }) => {
return <ListItem checked={node.checked} line={node.position?.start.line} children={node.children}/>;
},
listItem,
html: ({ node }, children) => {
const { sanitizer } = useSanitizer();
if (sanitizer !== undefined) {
Expand Down
13 changes: 0 additions & 13 deletions src/roles.ts

This file was deleted.

File renamed without changes.
File renamed without changes.
3 changes: 3 additions & 0 deletions src/transforms/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export * from './citations';
export * from './images';
export * from './links';
File renamed without changes.
1 change: 1 addition & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ 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
Loading
Loading