-
-
Notifications
You must be signed in to change notification settings - Fork 722
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add remark-slate source code to Plate (#2175)
Add tests for deserializeMd Add relevent parts of remark-slate Linter fixes Fix function exports Move element types out of options Replace custom types with Plate types Refactor deserialization rules into options Fix blockquotes Drop strikethrough support Fix images Fix code blocks Fix lists Fix <br> Fix generics Make rules configurable through Plate plugin options Fix images (again) Add changesets
- Loading branch information
Showing
20 changed files
with
716 additions
and
93 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
'@udecode/plate-serializer-md': minor | ||
--- | ||
|
||
- Plugin can now be customised using `elementRules` and `textRules` options | ||
- Various fixes |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 31 additions & 20 deletions
51
packages/serializers/md/src/deserializer/createDeserializeMdPlugin.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,40 @@ | ||
import { createPluginFactory, isUrl } from '@udecode/plate-core'; | ||
import { createPluginFactory, isUrl, Value } from '@udecode/plate-core'; | ||
import { | ||
remarkDefaultElementRules, | ||
remarkDefaultTextRules, | ||
} from '../remark-slate'; | ||
import { DeserializeMdPlugin } from './types'; | ||
import { deserializeMd } from './utils'; | ||
|
||
export const KEY_DESERIALIZE_MD = 'deserializeMd'; | ||
|
||
export const createDeserializeMdPlugin = createPluginFactory({ | ||
key: KEY_DESERIALIZE_MD, | ||
then: (editor) => ({ | ||
editor: { | ||
insertData: { | ||
format: 'text/plain', | ||
query: ({ data, dataTransfer }) => { | ||
const htmlData = dataTransfer.getData('text/html'); | ||
if (htmlData) return false; | ||
export const createDeserializeMdPlugin = createPluginFactory<DeserializeMdPlugin>( | ||
{ | ||
key: KEY_DESERIALIZE_MD, | ||
then: (editor) => ({ | ||
editor: { | ||
insertData: { | ||
format: 'text/plain', | ||
query: ({ data, dataTransfer }) => { | ||
const htmlData = dataTransfer.getData('text/html'); | ||
if (htmlData) return false; | ||
|
||
const { files } = dataTransfer; | ||
if (!files?.length) { | ||
// if content is simply a URL pass through to not break LinkPlugin | ||
if (isUrl(data)) { | ||
return false; | ||
const { files } = dataTransfer; | ||
if (!files?.length) { | ||
// if content is simply a URL pass through to not break LinkPlugin | ||
if (isUrl(data)) { | ||
return false; | ||
} | ||
} | ||
} | ||
return true; | ||
return true; | ||
}, | ||
getFragment: ({ data }) => deserializeMd<Value>(editor, data), | ||
}, | ||
getFragment: ({ data }) => deserializeMd(editor, data), | ||
}, | ||
}), | ||
options: { | ||
elementRules: remarkDefaultElementRules, | ||
textRules: remarkDefaultTextRules, | ||
}, | ||
}), | ||
}); | ||
} | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,4 +3,5 @@ | |
*/ | ||
|
||
export * from './createDeserializeMdPlugin'; | ||
export * from './types'; | ||
export * from './utils/index'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import { Value } from '@udecode/plate-core'; | ||
import { RemarkElementRules, RemarkTextRules } from '../remark-slate'; | ||
|
||
export interface DeserializeMdPlugin<V extends Value = Value> { | ||
elementRules: RemarkElementRules<V>; | ||
textRules: RemarkTextRules<V>; | ||
} |
Oops, something went wrong.
b42d095
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
plate-examples – ./
plate-examples-udecode.vercel.app
plate-examples-git-main-udecode.vercel.app
plate-examples.vercel.app
b42d095
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
plate – ./
plate-udecode.vercel.app
plate.udecode.io
www.plate.udecode.io
plate-git-main-udecode.vercel.app