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

Stop parsing unsupported GFM syntax features (footnotes and task lists) in fields.mdx #1311

Merged
merged 1 commit into from
Sep 13, 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
5 changes: 5 additions & 0 deletions .changeset/nice-pianos-whisper.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@keystatic/core': patch
---

Stop parsing unsupported GFM syntax features (footnotes and task lists) in `fields.mdx`
4 changes: 2 additions & 2 deletions packages/keystatic/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -153,14 +153,14 @@
"lru-cache": "^10.2.0",
"match-sorter": "^6.3.1",
"mdast-util-from-markdown": "^2.0.0",
"mdast-util-gfm": "^3.0.0",
"mdast-util-gfm-autolink-literal": "^2.0.0",
"mdast-util-gfm-strikethrough": "^2.0.0",
"mdast-util-gfm-table": "^2.0.0",
"mdast-util-mdx": "^3.0.0",
"mdast-util-to-markdown": "^2.1.0",
"micromark-extension-gfm": "^3.0.0",
"micromark-extension-gfm-autolink-literal": "^2.0.0",
"micromark-extension-gfm-strikethrough": "^2.0.0",
"micromark-extension-gfm-table": "^2.0.0",
"micromark-extension-mdxjs": "^3.0.0",
"minimatch": "^9.0.3",
"partysocket": "^0.0.22",
Expand Down
11 changes: 9 additions & 2 deletions packages/keystatic/src/form/fields/markdoc/editor/mdx/parse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ import { MdxJsxAttributeValueExpression, mdxToMarkdown } from 'mdast-util-mdx';
import { assert } from 'emery';
import { deserializeProps, toSerialized } from '../props-serialization';
import { toMarkdown } from 'mdast-util-to-markdown';
import { gfmToMarkdown } from 'mdast-util-gfm';
import { gfmAutolinkLiteralToMarkdown } from 'mdast-util-gfm-autolink-literal';
import { gfmStrikethroughToMarkdown } from 'mdast-util-gfm-strikethrough';
import { gfmTableToMarkdown } from 'mdast-util-gfm-table';

let state:
| {
Expand Down Expand Up @@ -445,7 +447,12 @@ function markdocNodeToProseMirrorNode(
if (node.type === 'definition') return [];
error(
`Unhandled type ${node.type}: ${toMarkdown(node, {
extensions: [gfmToMarkdown(), mdxToMarkdown()],
extensions: [
gfmAutolinkLiteralToMarkdown(),
gfmStrikethroughToMarkdown(),
gfmTableToMarkdown(),
mdxToMarkdown(),
],
rule: '-',
})}`
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,15 @@
import { EditorStateDescription, jsx, toEditorState } from './utils';
import { createEditorSchema, getEditorSchema } from '../schema';
import { editorOptionsToConfig } from '../../config';
import { gfmFromMarkdown, gfmToMarkdown } from 'mdast-util-gfm';
import {
gfmAutolinkLiteralFromMarkdown,
gfmAutolinkLiteralToMarkdown,
} from 'mdast-util-gfm-autolink-literal';
import {
gfmStrikethroughFromMarkdown,
gfmStrikethroughToMarkdown,
} from 'mdast-util-gfm-strikethrough';
import { gfmTableFromMarkdown, gfmTableToMarkdown } from 'mdast-util-gfm-table';
import { mdxFromMarkdown, mdxToMarkdown } from 'mdast-util-mdx';
import { toMarkdown } from 'mdast-util-to-markdown';
import { proseMirrorToMDXRoot } from '../mdx/serialize';
Expand All @@ -14,7 +22,9 @@ import { mdxToProseMirror } from '../mdx/parse';
import { expect, test } from '@jest/globals';
import { block, inline, mark } from '../../../../../content-components';
import { fields } from '../../../../..';
import { gfm } from 'micromark-extension-gfm';
import { gfmAutolinkLiteral } from 'micromark-extension-gfm-autolink-literal';
import { gfmStrikethrough } from 'micromark-extension-gfm-strikethrough';
import { gfmTable } from 'micromark-extension-gfm-table';

const schema = createEditorSchema(
editorOptionsToConfig({}),
Expand Down Expand Up @@ -72,15 +82,25 @@ function toMDX(node: EditorStateDescription) {
slug: undefined,
});
return toMarkdown(mdxNode, {
extensions: [gfmToMarkdown(), mdxToMarkdown()],
extensions: [
gfmAutolinkLiteralToMarkdown(),
gfmStrikethroughToMarkdown(),
gfmTableToMarkdown(),
mdxToMarkdown(),
],
rule: '-',
});
}

function fromMDX(mdx: string) {
const root = fromMarkdown(mdx, {
extensions: [mdxjs(), gfm()],
mdastExtensions: [mdxFromMarkdown(), gfmFromMarkdown()],
extensions: [mdxjs(), gfmAutolinkLiteral(), gfmStrikethrough(), gfmTable()],
mdastExtensions: [
mdxFromMarkdown(),
gfmAutolinkLiteralFromMarkdown(),
gfmStrikethroughFromMarkdown(),
gfmTableFromMarkdown(),
],
});
const files = new Map<string, Uint8Array>([
['something something.png', new Uint8Array([])],
Expand Down
30 changes: 25 additions & 5 deletions packages/keystatic/src/form/fields/markdoc/ui.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,19 @@ import { proseMirrorToMarkdoc } from './editor/markdoc/serialize';
import { useEntryLayoutSplitPaneContext } from '../../../app/entry-form';
import { fromMarkdown } from 'mdast-util-from-markdown';
import { toMarkdown } from 'mdast-util-to-markdown';
import { gfmFromMarkdown, gfmToMarkdown } from 'mdast-util-gfm';
import {
gfmAutolinkLiteralFromMarkdown,
gfmAutolinkLiteralToMarkdown,
} from 'mdast-util-gfm-autolink-literal';
import {
gfmStrikethroughFromMarkdown,
gfmStrikethroughToMarkdown,
} from 'mdast-util-gfm-strikethrough';
import { gfmTableFromMarkdown, gfmTableToMarkdown } from 'mdast-util-gfm-table';
import { mdxFromMarkdown, mdxToMarkdown } from 'mdast-util-mdx';
import { gfm } from 'micromark-extension-gfm';
import { gfmAutolinkLiteral } from 'micromark-extension-gfm-autolink-literal';
import { gfmStrikethrough } from 'micromark-extension-gfm-strikethrough';
import { gfmTable } from 'micromark-extension-gfm-table';
import { mdxjs } from 'micromark-extension-mdxjs';
import * as Y from 'yjs';
import { mdxToProseMirror } from './editor/mdx/parse';
Expand Down Expand Up @@ -71,8 +81,13 @@ export function parseToEditorStateMDX(
slug: string | undefined
) {
const root = fromMarkdown(content, {
extensions: [mdxjs(), gfm()],
mdastExtensions: [mdxFromMarkdown(), gfmFromMarkdown()],
extensions: [mdxjs(), gfmAutolinkLiteral(), gfmStrikethrough(), gfmTable()],
mdastExtensions: [
mdxFromMarkdown(),
gfmAutolinkLiteralFromMarkdown(),
gfmStrikethroughFromMarkdown(),
gfmTableFromMarkdown(),
],
});
const doc = mdxToProseMirror(root, schema, files, otherFiles, slug);
return createEditorState(doc);
Expand All @@ -91,7 +106,12 @@ export function serializeFromEditorStateMDX(
slug,
});
const mdx = toMarkdown(mdxNode, {
extensions: [gfmToMarkdown(), mdxToMarkdown()],
extensions: [
gfmAutolinkLiteralToMarkdown(),
gfmStrikethroughToMarkdown(),
gfmTableToMarkdown(),
mdxToMarkdown(),
],
rule: '-',
});
return {
Expand Down
12 changes: 6 additions & 6 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading