You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+32-2Lines changed: 32 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -128,8 +128,9 @@ Since entities can also contain additional custom information - in this case, th
128
128
129
129
What if you wanted to go the opposite direction? markdownToDraft uses [Remarkable](https://github.com/jonschlinkert/remarkable) for defining custom markdown types.
130
130
131
-
In this case, you need to write a [remarkable plugin](https://github.com/jonschlinkert/remarkable/blob/master/docs/plugins.md) first and pass it in to `markdownToDraft` -
131
+
In this case, you need to write a [remarkable plugin](https://github.com/jonschlinkert/remarkable/blob/master/docs/plugins.md) first and pass it in to `markdownToDraft`. You can find an example of Remarkable plugin in [this repository tests](https://github.com/Rosey/markdown-draft-js/blob/main/test/markdown-to-draft.spec.js#L369).
132
132
133
+
Example to convert a custom Remarkable token `mention_open` to a Draft entity:
133
134
```javascript
134
135
var rawDraftJSObject =markdownToDraft(markdownString, {
135
136
remarkablePlugins: [remarkableMentionPlugin],
@@ -146,10 +147,39 @@ var rawDraftJSObject = markdownToDraft(markdownString, {
146
147
}
147
148
};
148
149
}
149
-
}
150
+
},
151
+
});
152
+
```
153
+
Example to convert a custom Remarkable token `atomic` to a Draft block:
154
+
```javascript
155
+
var rawDraftJSObject =markdownToDraft(markdownString, {
156
+
remarkablePlugins: [remarkableMentionPlugin],
157
+
blockTypes: {
158
+
atomic_block:function (item) {
159
+
return {
160
+
type:"atomic",
161
+
text:item.content,
162
+
entityRanges: [],
163
+
inlineStyleRanges: [],
164
+
}
165
+
}
166
+
},
150
167
});
151
168
```
152
169
170
+
If your custom Remarkable plugin returns a standalone token, you can specify it
171
+
in the configuration:
172
+
```javascript
173
+
var rawDraftJSObject =markdownToDraft(markdownString, {
0 commit comments