Skip to content

Commit 5ce227f

Browse files
committed
Merge branch 'main' into fix/stream
2 parents 368c12d + f999949 commit 5ce227f

18 files changed

Lines changed: 595 additions & 46 deletions

File tree

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

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ Configuring `MarkdownPlugin` is recommended to enable paste handling (converting
4747

4848
```tsx
4949
import { createPlateEditor } from '@udecode/plate/react';
50-
import { MarkdownPlugin } from '@udecode/plate-markdown';
50+
import { MarkdownPlugin, remarkMention } from '@udecode/plate-markdown';
5151
import remarkGfm from 'remark-gfm';
5252
import remarkMath from 'remark-math';
5353
import remarkMdx from 'remark-mdx';
@@ -58,7 +58,7 @@ const editor = createPlateEditor({
5858
MarkdownPlugin.configure({
5959
options: {
6060
// Add remark plugins for syntax extensions (GFM, Math, MDX)
61-
remarkPlugins: [remarkMath, remarkGfm, remarkMdx],
61+
remarkPlugins: [remarkMath, remarkGfm, remarkMdx, remarkMention],
6262
// Define custom rules for serialization/deserialization if needed
6363
rules: {
6464
// Example: custom rule for a 'date' element
@@ -161,7 +161,11 @@ import type { MdMdxJsxTextElement } from '@udecode/plate-markdown'; // Import ty
161161
MarkdownPlugin.configure({
162162
options: {
163163
rules: {
164-
date: { // Key matches the plugin 'key' or 'type' of the Slate element
164+
// Key matches:
165+
// 1. the plugin 'key' or 'type' of the Slate element.
166+
// 2. the mdast(https://github.com/syntax-tree/mdast) node type.
167+
// 3. the mdx tag name.
168+
date: {
165169
// Rule for Markdown -> Slate
166170
deserialize(mdastNode: MdMdxJsxTextElement, deco, options) {
167171
// Extract data from the MDX node attributes or children
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
import { MarkdownPlugin } from '@udecode/plate-markdown';
1+
import { MarkdownPlugin, remarkMention } from '@udecode/plate-markdown';
22
import { SuggestionPlugin } from '@udecode/plate-suggestion/react';
33
import remarkGfm from 'remark-gfm';
44
import remarkMath from 'remark-math';
55
import remarkMdx from 'remark-mdx';
66
export const markdownPlugin = MarkdownPlugin.configure({
77
options: {
88
disallowedNodes: [SuggestionPlugin.key],
9-
remarkPlugins: [remarkMath, remarkGfm, remarkMdx],
9+
remarkPlugins: [remarkMath, remarkGfm, remarkMdx, remarkMention],
1010
},
1111
});

apps/www/src/registry/default/examples/markdown-to-slate-demo.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import { HighlightPlugin } from '@udecode/plate-highlight/react';
2222
import { HorizontalRulePlugin } from '@udecode/plate-horizontal-rule/react';
2323
import { KbdPlugin } from '@udecode/plate-kbd/react';
2424
import { LinkPlugin } from '@udecode/plate-link/react';
25-
import { MarkdownPlugin } from '@udecode/plate-markdown';
25+
import { MarkdownPlugin, remarkMention } from '@udecode/plate-markdown';
2626
import { InlineEquationPlugin } from '@udecode/plate-math/react';
2727
import { ImagePlugin } from '@udecode/plate-media/react';
2828
import { MentionPlugin } from '@udecode/plate-mention/react';
@@ -216,7 +216,7 @@ export default function MarkdownDemo() {
216216
autoformatPlugin,
217217
MarkdownPlugin.configure({
218218
options: {
219-
remarkPlugins: [remarkMath, remarkGfm, remarkMdx],
219+
remarkPlugins: [remarkMath, remarkGfm, remarkMdx, remarkMention],
220220
},
221221
}),
222222
MentionPlugin.configure({

packages/ai/CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# @udecode/plate-ai
22

3+
## 47.0.7
4+
5+
## 47.0.6
6+
7+
## 47.0.5
8+
39
## 47.0.4
410

511
## 47.0.3

packages/ai/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@udecode/plate-ai",
3-
"version": "47.0.4",
3+
"version": "47.0.7",
44
"description": "Text AI plugin for Plate",
55
"keywords": [
66
"plate",
@@ -50,7 +50,7 @@
5050
"typecheck": "yarn p:typecheck"
5151
},
5252
"dependencies": {
53-
"@udecode/plate-markdown": "47.0.4",
53+
"@udecode/plate-markdown": "47.0.7",
5454
"@udecode/plate-selection": "46.0.4",
5555
"lodash": "^4.17.21"
5656
},

packages/markdown/CHANGELOG.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,27 @@
11
# @udecode/plate-markdown
22

3+
## 47.0.7
4+
5+
### Patch Changes
6+
7+
- [#4216](https://github.com/udecode/plate/pull/4216) by [@martin-lysk](https://github.com/martin-lysk) – linebreaks (soft linebreaks and paragraphs) are serialized and deserialized differently now
8+
9+
## 47.0.6
10+
11+
### Patch Changes
12+
13+
- [#4215](https://github.com/udecode/plate/pull/4215) by [@martin-lysk](https://github.com/martin-lysk) – removes lodash dependency
14+
15+
- [#4214](https://github.com/udecode/plate/pull/4214) by [@felixfeng33](https://github.com/felixfeng33) – Make remarkMention plugin optional.
16+
17+
## 47.0.5
18+
19+
### Patch Changes
20+
21+
- [#4200](https://github.com/udecode/plate/pull/4200) by [@martin-lysk](https://github.com/martin-lysk) – fixes blockquote serialization/deserialization, adds break deserialization
22+
23+
- [#4211](https://github.com/udecode/plate/pull/4211) by [@martin-lysk](https://github.com/martin-lysk) – adds explicit spread false to lists to have a less noisy serialization
24+
325
## 47.0.4
426

527
### Patch Changes

packages/markdown/package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@udecode/plate-markdown",
3-
"version": "47.0.4",
3+
"version": "47.0.7",
44
"description": "Markdown serializer plugin for Plate",
55
"keywords": [
66
"markdown",
@@ -47,7 +47,6 @@
4747
"typecheck": "yarn p:typecheck"
4848
},
4949
"dependencies": {
50-
"lodash": "^4.17.21",
5150
"marked": "^15.0.6",
5251
"mdast-util-math": "3.0.0",
5352
"mdast-util-mdx": "3.0.0",

packages/markdown/src/lib/deserializer/deserializeMd.spec.tsx

Lines changed: 94 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,96 @@ describe('deserializeMd', () => {
6767
expect(deserializeMd(editor, input)).toEqual(output);
6868
});
6969

70+
it('should deserialize paragraphts in blockquotes as two breaks', () => {
71+
const input = `> Blockquote paragraph1
72+
>
73+
> Blockquote paragraph2`;
74+
75+
const output = (
76+
<fragment>
77+
<hblockquote>
78+
<htext>Blockquote paragraph1</htext>
79+
<htext>{'\n'}</htext>
80+
<htext>{'\n'}</htext>
81+
<htext>Blockquote paragraph2</htext>
82+
</hblockquote>
83+
</fragment>
84+
);
85+
86+
expect(deserializeMd(editor, input)).toEqual(output);
87+
});
88+
89+
it(
90+
String.raw`should deserialize two spaces followed by a \n in blockquotes`,
91+
() => {
92+
const input = `
93+
> Blockquote line1
94+
> Blockquote line2`;
95+
96+
const output = (
97+
<fragment>
98+
<hblockquote>
99+
<htext>Blockquote line1</htext>
100+
<htext>{'\n'}</htext>
101+
<htext>Blockquote line2</htext>
102+
</hblockquote>
103+
</fragment>
104+
);
105+
106+
expect(deserializeMd(editor, input)).toEqual(output);
107+
}
108+
);
109+
110+
it(
111+
String.raw`should deserialize a break followed by a \n to one line break - collapsing break`,
112+
() => {
113+
const input = `
114+
> Blockquote line1<br>
115+
> Blockquote line2`;
116+
117+
const output = (
118+
<fragment>
119+
<hblockquote>
120+
<htext>Blockquote line1</htext>
121+
<htext>{'\n'}</htext>
122+
<htext>Blockquote line2</htext>
123+
</hblockquote>
124+
</fragment>
125+
);
126+
127+
expect(deserializeMd(editor, input)).toEqual(output);
128+
}
129+
);
130+
131+
it(
132+
String.raw`should convert in blockqoute line breaks into two breaks`,
133+
() => {
134+
const input = `
135+
> Blockquote with multiple paragraphs:\\
136+
> \\
137+
> This is the second paragraph in the blockquote.`;
138+
139+
const output = (
140+
<fragment>
141+
<hblockquote>
142+
<htext>Blockquote with multiple paragraphs:</htext>
143+
<htext>{'\n'}</htext>
144+
<htext>{'\n'}</htext>
145+
<htext>This is the second paragraph in the blockquote.</htext>
146+
</hblockquote>
147+
</fragment>
148+
);
149+
150+
expect(deserializeMd(editor, input)).toEqual(output);
151+
}
152+
);
153+
70154
it('should deserialize paragraphs', () => {
71-
const input =
72-
'Paragraph 1 line 1\nParagraph 1 line 2\n\nParagraph 2 line 1';
155+
const input = `
156+
Paragraph 1 line 1
157+
Paragraph 1 line 2
158+
159+
Paragraph 2 line 1`;
73160

74161
const output = (
75162
<fragment>
@@ -85,8 +172,11 @@ describe('deserializeMd', () => {
85172
});
86173

87174
it('should deserialize blockquotes', () => {
88-
const input =
89-
'> Blockquote 1 line 1\n> Blockquote 1 line 2\n\n> Blockquote 2 line 1';
175+
const input = `
176+
> Blockquote 1 line 1
177+
> Blockquote 1 line 2
178+
179+
> Blockquote 2 line 1`;
90180

91181
const output = (
92182
<fragment>

packages/markdown/src/lib/deserializer/deserializeMd.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import { unified } from 'unified';
88
import type { AllowNodeConfig, NodesConfig } from '../MarkdownPlugin';
99
import type { TRules } from '../rules';
1010

11-
import { remarkMention } from '../plugins/remarkMention';
1211
import { mdastToSlate } from './mdastToSlate';
1312
import { type ParseMarkdownBlocksOptions, parseMarkdownBlocks } from './utils';
1413
import { getMergedOptionsDeserialize } from './utils/getMergedOptionsDeserialize';
@@ -40,7 +39,6 @@ export const deserializeMd = (
4039
const toSlateProcessor = unified()
4140
.use(remarkParse)
4241
.use(mergedOptions.remarkPlugins ?? [])
43-
.use(remarkMention)
4442
.use(remarkToSlate, mergedOptions);
4543

4644
if (options?.memoize) {

0 commit comments

Comments
 (0)