Skip to content

Commit 5153efc

Browse files
authored
Merge pull request #4288 from udecode/md/custom
Support non-standard markdown nodes
2 parents 36d1a51 + 258a720 commit 5153efc

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+2397
-531
lines changed

.changeset/new-baboons-push.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
---
2+
'@udecode/plate-markdown': patch
3+
---
4+
5+
Added support for `subscript`, `superscript`, `date`, `callout`, `font`.
6+
7+
Replaced dependency on `zeed-dom` with `remark-mdx` for more robust MDX tag generation.
8+
9+
Add `splitIncompleteMdx` to separate the complete and the incomplete mdx string.

.changeset/tiny-mangos-pay.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@udecode/plate-ai': patch
3+
---
4+
5+
Fix test case and missing import

apps/www/content/docs/en/components/changelog.mdx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,12 @@ Use the [CLI](https://platejs.org/docs/components/cli) to install the latest ver
1010

1111
## May 2025 #22
1212

13+
### May 6 #22.3
14+
15+
- `ai-chat-editor`: support none-standard markdown nodes.
16+
- `slash-input-element`: add callout support.
17+
- `block-selection-plugins.tsx`: fix block selection not working.
18+
1319
### May 4 #22.2
1420

1521
- `ai/command`: forked smoothStream from `ai` package now uses 30ms delay by default (only code blocks and tables use 100ms delay).

apps/www/content/docs/en/markdown.mdx

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -790,6 +790,33 @@ Here's a summary of some key default conversions. See [`defaultRules.ts`](https:
790790

791791
* The conversion target for lists (`ol`/`ul` vs. `p` with indent props) depends on whether `IndentListPlugin` is detected in the editor configuration.
792792

793+
---
794+
795+
The following table summarizes the default MDX conversions supported when using `remark-mdx`.
796+
797+
| Mdx(mdast) | Plate Type | Notes |
798+
| :---------------- | :------------------- | :--------------------------------------- |
799+
| `<del>...</del>` | `strikethrough` (mark) | Alternative to `~~strikethrough~~` |
800+
| `<sub>...</sub>` | `subscript` (mark) | Text like H<sub>2</sub>O |
801+
| `<sup>...</sup>` | `superscript` (mark) | Text like E=mc<sup>2</sup> |
802+
| `<u>...</u>` | `underline` (mark) | <u>Underlined text</u> |
803+
| `<mark>...</mark>` | `highlight` (mark) | <mark>Highlighted text</mark> |
804+
| `<span style="font-family: ...">...</span>` | `fontFamily` (mark) | Changes text font family |
805+
| `<span style="font-size: ...">...</span>` | `fontSize` (mark) | Changes text size |
806+
| `<span style="font-weight: ...">...</span>` | `fontWeight` (mark) | Changes text weight (bold, etc.) |
807+
| `<span style="color: ...">...</span>` | `color` (mark) | Changes text color |
808+
| `<span style="background-color: ...">...</span>` | `backgroundColor` (mark) | Changes text background color |
809+
| `<date>...</date>` | `date` | Date element |
810+
| `@mention` | `mention` | Mention element |
811+
| `<file name="..." src="..." />` | `file` | File attachment/embed |
812+
| `<audio src="..." />` | `audio` | Audio player embed |
813+
| `<video src="..." />` | `video` | Video player embed |
814+
| `<toc />` | `toc` | table of contents |
815+
| `<callout>...</callout>` | `callout` | highlight callout |
816+
| `<column_group>...</column_group>` | `column_group` | multi-column layout |
817+
| `<column>...</column>` | `column` | single column layout |
818+
819+
793820
## Appendix C: Components
794821

795822
While `rules` customize the *conversion* between Markdown and Slate, Plate uses React components to *render* the Slate nodes in the editor. You can configure these rendering components using the `components` option in `createPlateEditor`.

apps/www/src/registry/default/blocks/editor-ai/components/editor/use-create-editor.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import {
1414
UnderlinePlugin,
1515
} from '@udecode/plate-basic-marks/react';
1616
import { BlockquotePlugin } from '@udecode/plate-block-quote/react';
17+
import { CalloutPlugin } from '@udecode/plate-callout/react';
1718
import {
1819
CodeBlockPlugin,
1920
CodeLinePlugin,
@@ -68,6 +69,7 @@ import { FixedToolbarPlugin } from '@/registry/default/components/editor/plugins
6869
import { FloatingToolbarPlugin } from '@/registry/default/components/editor/plugins/floating-toolbar-plugin';
6970
import { AILeaf } from '@/registry/default/plate-ui/ai-leaf';
7071
import { BlockquoteElement } from '@/registry/default/plate-ui/blockquote-element';
72+
import { CalloutElement } from '@/registry/default/plate-ui/callout-element';
7173
import { CodeBlockElement } from '@/registry/default/plate-ui/code-block-element';
7274
import { CodeLeaf } from '@/registry/default/plate-ui/code-leaf';
7375
import { CodeLineElement } from '@/registry/default/plate-ui/code-line-element';
@@ -110,6 +112,7 @@ export const viewComponents = {
110112
[AudioPlugin.key]: MediaAudioElement,
111113
[BlockquotePlugin.key]: BlockquoteElement,
112114
[BoldPlugin.key]: withProps(PlateLeaf, { as: 'strong' }),
115+
[CalloutPlugin.key]: CalloutElement,
113116
[CodeBlockPlugin.key]: CodeBlockElement,
114117
[CodeLinePlugin.key]: CodeLineElement,
115118
[CodePlugin.key]: CodeLeaf,

apps/www/src/registry/default/components/editor/plugins/ai-plugins.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ Rules:
2626
- Your response should be tailored to the user's prompt, providing precise assistance to optimize note management.
2727
- For INSTRUCTIONS: Follow the <Reminder> exactly. Provide ONLY the content to be inserted or replaced. No explanations or comments.
2828
- For QUESTIONS: Provide a helpful and concise answer. You may include brief explanations if necessary.
29+
- CRITICAL: DO NOT remove or modify the following custom MDX tags: <u>, <callout>, <kbd>, <toc>, <sub>, <sup>, <mark>, <del>, <date>, <span>, <column>, <column_group>, <file>, <audio>, <video> in <Selection> unless the user explicitly requests this change.
2930
- CRITICAL: Distinguish between INSTRUCTIONS and QUESTIONS. Instructions typically ask you to modify or add content. Questions ask for information or clarification.
3031
- CRITICAL: when asked to write in markdown, do not start with \`\`\`markdown.
3132
`;

apps/www/src/registry/default/components/editor/plugins/block-selection-plugins.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ export const blockSelectionPlugins = [
1717
},
1818
render: {
1919
belowRootNodes: (props) => {
20-
if (!props.className?.includes('slate-selectable')) return null;
20+
if (!props.attributes.className?.includes('slate-selectable'))
21+
return null;
2122

2223
return <BlockSelection />;
2324
},

0 commit comments

Comments
 (0)