decap-cms-widget-markdown 3.3.0 → 3.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +10 -0
- package/dist/decap-cms-widget-markdown.js +6 -6
- package/dist/decap-cms-widget-markdown.js.LICENSE.txt +5 -5
- package/dist/decap-cms-widget-markdown.js.map +1 -1
- package/dist/esm/MarkdownControl/RawEditor.js +1 -2
- package/dist/esm/MarkdownControl/Toolbar.js +43 -47
- package/dist/esm/MarkdownControl/VisualEditor.js +6 -8
- package/dist/esm/MarkdownControl/components/Shortcode.js +6 -11
- package/dist/esm/MarkdownControl/components/VoidBlock.js +1 -1
- package/dist/esm/MarkdownControl/index.js +34 -34
- package/dist/esm/MarkdownControl/plugins/CommandsAndQueries.js +8 -8
- package/dist/esm/MarkdownControl/plugins/inlines/events/toggleLink.js +1 -2
- package/dist/esm/MarkdownControl/plugins/lists/events/keyDownShiftTab.js +6 -9
- package/dist/esm/MarkdownControl/plugins/lists/events/keyDownTab.js +3 -7
- package/dist/esm/MarkdownControl/plugins/lists/transforms/liftFirstMatchedParent.js +4 -8
- package/dist/esm/MarkdownControl/plugins/lists/transforms/unwrapSelectionFromList.js +3 -7
- package/dist/esm/MarkdownControl/plugins/util.js +4 -4
- package/dist/esm/MarkdownControl/renderers.js +6 -11
- package/dist/esm/MarkdownPreview.js +11 -10
- package/dist/esm/index.js +4 -8
- package/dist/esm/regexHelper.js +4 -3
- package/dist/esm/serializers/index.js +2 -2
- package/dist/esm/serializers/remarkAssertParents.js +17 -20
- package/dist/esm/serializers/remarkEscapeMarkdownEntities.js +17 -17
- package/dist/esm/serializers/remarkImagesToText.js +3 -7
- package/dist/esm/serializers/remarkPaddedLinks.js +17 -21
- package/dist/esm/serializers/remarkRehypeShortcodes.js +10 -13
- package/dist/esm/serializers/remarkSlate.js +64 -55
- package/dist/esm/serializers/remarkSquashReferences.js +7 -11
- package/dist/esm/serializers/slateRemark.js +52 -52
- package/package.json +9 -7
- package/src/MarkdownControl/Toolbar.js +5 -0
- package/src/MarkdownControl/VisualEditor.js +1 -1
- package/src/MarkdownControl/components/Shortcode.js +1 -1
- package/src/MarkdownControl/index.js +5 -0
- package/src/MarkdownControl/plugins/CommandsAndQueries.js +3 -1
- package/src/MarkdownControl/plugins/util.js +2 -1
- package/src/MarkdownPreview.js +5 -0
- package/src/__tests__/renderer.spec.js +84 -117
- package/src/regexHelper.js +1 -1
- package/src/serializers/__tests__/commonmark.spec.js +1 -1
- package/src/serializers/__tests__/slate.spec.js +1 -1
- package/src/serializers/index.js +1 -1
- package/src/serializers/remarkAssertParents.js +4 -1
- package/src/serializers/remarkEscapeMarkdownEntities.js +4 -1
- package/src/serializers/remarkPaddedLinks.js +7 -1
- package/src/serializers/remarkRehypeShortcodes.js +2 -1
- package/src/serializers/remarkSlate.js +6 -1
- package/src/serializers/remarkSquashReferences.js +2 -1
- package/src/serializers/slateRemark.js +6 -1
- package/src/__tests__/__snapshots__/renderer.spec.js.snap +0 -239
|
@@ -1,15 +1,10 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
import
|
|
7
|
-
import
|
|
8
|
-
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
9
|
-
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
10
|
-
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
11
|
-
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : String(i); }
|
|
12
|
-
function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
1
|
+
import find from 'lodash/find';
|
|
2
|
+
import findLast from 'lodash/findLast';
|
|
3
|
+
import startsWith from 'lodash/startsWith';
|
|
4
|
+
import endsWith from 'lodash/endsWith';
|
|
5
|
+
import trimStart from 'lodash/trimStart';
|
|
6
|
+
import trimEnd from 'lodash/trimEnd';
|
|
7
|
+
import flatMap from 'lodash/flatMap';
|
|
13
8
|
import u from 'unist-builder';
|
|
14
9
|
import toString from 'mdast-util-to-string';
|
|
15
10
|
|
|
@@ -41,15 +36,16 @@ export default function remarkPaddedLinks() {
|
|
|
41
36
|
* this seems unlikely to produce a noticeable perf gain.
|
|
42
37
|
*/
|
|
43
38
|
const hasLinkChild = node.children.some(child => child.type === 'link');
|
|
44
|
-
const processedChildren = hasLinkChild ?
|
|
39
|
+
const processedChildren = hasLinkChild ? flatMap(node.children, transformChildren) : node.children;
|
|
45
40
|
|
|
46
41
|
/**
|
|
47
42
|
* Run all children through the transform recursively.
|
|
48
43
|
*/
|
|
49
44
|
const children = processedChildren.map(transform);
|
|
50
|
-
return
|
|
45
|
+
return {
|
|
46
|
+
...node,
|
|
51
47
|
children
|
|
52
|
-
}
|
|
48
|
+
};
|
|
53
49
|
}
|
|
54
50
|
function transformChildren(node) {
|
|
55
51
|
if (node.type !== 'link') return node;
|
|
@@ -59,8 +55,8 @@ export default function remarkPaddedLinks() {
|
|
|
59
55
|
* whitespace, and get nodes from each edge where whitespace is found.
|
|
60
56
|
*/
|
|
61
57
|
const text = toString(node);
|
|
62
|
-
const leadingWhitespaceNode =
|
|
63
|
-
const trailingWhitespaceNode =
|
|
58
|
+
const leadingWhitespaceNode = startsWith(text, ' ') && getEdgeTextChild(node);
|
|
59
|
+
const trailingWhitespaceNode = endsWith(text, ' ') && getEdgeTextChild(node, true);
|
|
64
60
|
if (!leadingWhitespaceNode && !trailingWhitespaceNode) return node;
|
|
65
61
|
|
|
66
62
|
/**
|
|
@@ -69,10 +65,10 @@ export default function remarkPaddedLinks() {
|
|
|
69
65
|
* ASTs.
|
|
70
66
|
*/
|
|
71
67
|
if (leadingWhitespaceNode) {
|
|
72
|
-
leadingWhitespaceNode.value =
|
|
68
|
+
leadingWhitespaceNode.value = trimStart(leadingWhitespaceNode.value);
|
|
73
69
|
}
|
|
74
70
|
if (trailingWhitespaceNode) {
|
|
75
|
-
trailingWhitespaceNode.value =
|
|
71
|
+
trailingWhitespaceNode.value = trimEnd(trailingWhitespaceNode.value);
|
|
76
72
|
}
|
|
77
73
|
|
|
78
74
|
/**
|
|
@@ -96,9 +92,9 @@ export default function remarkPaddedLinks() {
|
|
|
96
92
|
*/
|
|
97
93
|
let findFn;
|
|
98
94
|
if (end) {
|
|
99
|
-
findFn =
|
|
95
|
+
findFn = findLast;
|
|
100
96
|
} else {
|
|
101
|
-
findFn =
|
|
97
|
+
findFn = find;
|
|
102
98
|
}
|
|
103
99
|
let edgeChildWithValue;
|
|
104
100
|
setEdgeChildWithValue(node);
|
|
@@ -1,11 +1,6 @@
|
|
|
1
|
-
import _has from "lodash/has";
|
|
2
|
-
import _map from "lodash/map";
|
|
3
|
-
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
4
|
-
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
5
|
-
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
6
|
-
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : String(i); }
|
|
7
|
-
function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
8
1
|
import React from 'react';
|
|
2
|
+
import map from 'lodash/map';
|
|
3
|
+
import has from 'lodash/has';
|
|
9
4
|
import { renderToString } from 'react-dom/server';
|
|
10
5
|
import u from 'unist-builder';
|
|
11
6
|
|
|
@@ -22,10 +17,11 @@ export default function remarkToRehypeShortcodes({
|
|
|
22
17
|
}) {
|
|
23
18
|
return transform;
|
|
24
19
|
function transform(root) {
|
|
25
|
-
const transformedChildren =
|
|
26
|
-
return
|
|
20
|
+
const transformedChildren = map(root.children, processShortcodes);
|
|
21
|
+
return {
|
|
22
|
+
...root,
|
|
27
23
|
children: transformedChildren
|
|
28
|
-
}
|
|
24
|
+
};
|
|
29
25
|
}
|
|
30
26
|
|
|
31
27
|
/**
|
|
@@ -35,7 +31,7 @@ export default function remarkToRehypeShortcodes({
|
|
|
35
31
|
/**
|
|
36
32
|
* If the node doesn't contain shortcode data, return the original node.
|
|
37
33
|
*/
|
|
38
|
-
if (!
|
|
34
|
+
if (!has(node, ['data', 'shortcode'])) return node;
|
|
39
35
|
|
|
40
36
|
/**
|
|
41
37
|
* Get shortcode data from the node, and retrieve the matching plugin by
|
|
@@ -60,9 +56,10 @@ export default function remarkToRehypeShortcodes({
|
|
|
60
56
|
*/
|
|
61
57
|
const textNode = u('html', valueHtml);
|
|
62
58
|
const children = [textNode];
|
|
63
|
-
return
|
|
59
|
+
return {
|
|
60
|
+
...node,
|
|
64
61
|
children
|
|
65
|
-
}
|
|
62
|
+
};
|
|
66
63
|
}
|
|
67
64
|
|
|
68
65
|
/**
|
|
@@ -1,14 +1,10 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
import
|
|
7
|
-
|
|
8
|
-
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
9
|
-
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
10
|
-
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : String(i); }
|
|
11
|
-
function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
1
|
+
import isEmpty from 'lodash/isEmpty';
|
|
2
|
+
import isArray from 'lodash/isArray';
|
|
3
|
+
import flatMap from 'lodash/flatMap';
|
|
4
|
+
import map from 'lodash/map';
|
|
5
|
+
import flatten from 'lodash/flatten';
|
|
6
|
+
import isEqual from 'lodash/isEqual';
|
|
7
|
+
|
|
12
8
|
/**
|
|
13
9
|
* Map of MDAST node types to Slate node types.
|
|
14
10
|
*/
|
|
@@ -40,7 +36,7 @@ function isText(node) {
|
|
|
40
36
|
return !!node.text;
|
|
41
37
|
}
|
|
42
38
|
function isMarksEqual(node1, node2) {
|
|
43
|
-
return
|
|
39
|
+
return isEqual(node1.marks, node2.marks);
|
|
44
40
|
}
|
|
45
41
|
export function mergeAdjacentTexts(children) {
|
|
46
42
|
if (children.length <= 0) {
|
|
@@ -56,9 +52,10 @@ export function mergeAdjacentTexts(children) {
|
|
|
56
52
|
const next = children[i + 1];
|
|
57
53
|
if (isText(current) && isText(next) && isMarksEqual(current, next)) {
|
|
58
54
|
isMerging = true;
|
|
59
|
-
current =
|
|
55
|
+
current = {
|
|
56
|
+
...current,
|
|
60
57
|
text: `${current.text}${next.text}`
|
|
61
|
-
}
|
|
58
|
+
};
|
|
62
59
|
} else {
|
|
63
60
|
mergedChildren.push(current);
|
|
64
61
|
isMerging = false;
|
|
@@ -88,7 +85,7 @@ export default function remarkToSlate({
|
|
|
88
85
|
* translate from MDAST to Slate, such as definitions for link/image
|
|
89
86
|
* references or footnotes.
|
|
90
87
|
*/
|
|
91
|
-
let children = !['strong', 'emphasis', 'delete'].includes(node.type) && !
|
|
88
|
+
let children = !['strong', 'emphasis', 'delete'].includes(node.type) && !isEmpty(node.children) && flatMap(node.children, transformNode).filter(val => val);
|
|
92
89
|
if (Array.isArray(children)) {
|
|
93
90
|
// Merge adjacent text nodes with the same marks to conform to slate schema
|
|
94
91
|
children = mergeAdjacentTexts(children);
|
|
@@ -105,25 +102,27 @@ export default function remarkToSlate({
|
|
|
105
102
|
* Add nodes to a parent node only if `nodes` is truthy.
|
|
106
103
|
*/
|
|
107
104
|
function addNodes(parent, nodes) {
|
|
108
|
-
return nodes ?
|
|
105
|
+
return nodes ? {
|
|
106
|
+
...parent,
|
|
109
107
|
children: nodes
|
|
110
|
-
}
|
|
108
|
+
} : parent;
|
|
111
109
|
}
|
|
112
110
|
|
|
113
111
|
/**
|
|
114
112
|
* Create a Slate Block node.
|
|
115
113
|
*/
|
|
116
114
|
function createBlock(type, nodes, props = {}) {
|
|
117
|
-
if (!
|
|
115
|
+
if (!isArray(nodes)) {
|
|
118
116
|
props = nodes;
|
|
119
117
|
nodes = undefined;
|
|
120
118
|
}
|
|
121
119
|
|
|
122
120
|
// Ensure block nodes have at least one text child to conform to slate schema
|
|
123
|
-
const children =
|
|
124
|
-
const node =
|
|
125
|
-
type
|
|
126
|
-
|
|
121
|
+
const children = isEmpty(nodes) ? [createText('')] : nodes;
|
|
122
|
+
const node = {
|
|
123
|
+
type,
|
|
124
|
+
...props
|
|
125
|
+
};
|
|
127
126
|
return addNodes(node, children);
|
|
128
127
|
}
|
|
129
128
|
|
|
@@ -131,12 +130,13 @@ export default function remarkToSlate({
|
|
|
131
130
|
* Create a Slate Inline node.
|
|
132
131
|
*/
|
|
133
132
|
function createInline(type, props = {}, nodes) {
|
|
134
|
-
const node =
|
|
135
|
-
type
|
|
136
|
-
|
|
133
|
+
const node = {
|
|
134
|
+
type,
|
|
135
|
+
...props
|
|
136
|
+
};
|
|
137
137
|
|
|
138
138
|
// Ensure inline nodes have at least one text child to conform to slate schema
|
|
139
|
-
const children =
|
|
139
|
+
const children = isEmpty(nodes) ? [createText('')] : nodes;
|
|
140
140
|
return addNodes(node, children);
|
|
141
141
|
}
|
|
142
142
|
|
|
@@ -146,18 +146,20 @@ export default function remarkToSlate({
|
|
|
146
146
|
function createText(node) {
|
|
147
147
|
const newNode = {};
|
|
148
148
|
if (typeof node === 'string') {
|
|
149
|
-
return
|
|
149
|
+
return {
|
|
150
|
+
...newNode,
|
|
150
151
|
text: node
|
|
151
|
-
}
|
|
152
|
+
};
|
|
152
153
|
}
|
|
153
154
|
const {
|
|
154
155
|
text,
|
|
155
156
|
marks
|
|
156
157
|
} = node;
|
|
157
|
-
return normalizeMarks(
|
|
158
|
+
return normalizeMarks({
|
|
159
|
+
...newNode,
|
|
158
160
|
text,
|
|
159
161
|
marks
|
|
160
|
-
})
|
|
162
|
+
});
|
|
161
163
|
}
|
|
162
164
|
function processMarkChild(childNode, marks) {
|
|
163
165
|
switch (childNode.type) {
|
|
@@ -168,9 +170,10 @@ export default function remarkToSlate({
|
|
|
168
170
|
*/
|
|
169
171
|
case 'html':
|
|
170
172
|
case 'text':
|
|
171
|
-
return
|
|
173
|
+
return {
|
|
174
|
+
...convertNode(childNode),
|
|
172
175
|
marks
|
|
173
|
-
}
|
|
176
|
+
};
|
|
174
177
|
|
|
175
178
|
/**
|
|
176
179
|
* MDAST inline code nodes don't have children, just a text value, similar
|
|
@@ -179,11 +182,12 @@ export default function remarkToSlate({
|
|
|
179
182
|
*/
|
|
180
183
|
case 'inlineCode':
|
|
181
184
|
{
|
|
182
|
-
return
|
|
185
|
+
return {
|
|
186
|
+
...convertNode(childNode),
|
|
183
187
|
marks: [...marks, {
|
|
184
188
|
type: 'code'
|
|
185
189
|
}]
|
|
186
|
-
}
|
|
190
|
+
};
|
|
187
191
|
}
|
|
188
192
|
|
|
189
193
|
/**
|
|
@@ -198,8 +202,8 @@ export default function remarkToSlate({
|
|
|
198
202
|
return processMarkNode(childNode, marks);
|
|
199
203
|
case 'link':
|
|
200
204
|
{
|
|
201
|
-
const nodes =
|
|
202
|
-
const result = convertNode(childNode,
|
|
205
|
+
const nodes = map(childNode.children, child => normalizeMarks(processMarkChild(child, marks)));
|
|
206
|
+
const result = convertNode(childNode, flatten(nodes));
|
|
203
207
|
return result;
|
|
204
208
|
}
|
|
205
209
|
|
|
@@ -208,11 +212,13 @@ export default function remarkToSlate({
|
|
|
208
212
|
* added into the cumulative children array.
|
|
209
213
|
*/
|
|
210
214
|
default:
|
|
211
|
-
return transformNode(
|
|
212
|
-
|
|
215
|
+
return transformNode({
|
|
216
|
+
...childNode,
|
|
217
|
+
data: {
|
|
218
|
+
...childNode.data,
|
|
213
219
|
marks
|
|
214
|
-
}
|
|
215
|
-
})
|
|
220
|
+
}
|
|
221
|
+
});
|
|
216
222
|
}
|
|
217
223
|
}
|
|
218
224
|
function processMarkNode(node, parentMarks = []) {
|
|
@@ -226,7 +232,7 @@ export default function remarkToSlate({
|
|
|
226
232
|
}) => type !== markType), {
|
|
227
233
|
type: markType
|
|
228
234
|
}] : parentMarks;
|
|
229
|
-
const children =
|
|
235
|
+
const children = flatMap(node.children, child => normalizeMarks(processMarkChild(child, marks)));
|
|
230
236
|
return children;
|
|
231
237
|
}
|
|
232
238
|
function normalizeMarks(node) {
|
|
@@ -265,7 +271,7 @@ export default function remarkToSlate({
|
|
|
265
271
|
*/
|
|
266
272
|
case 'root':
|
|
267
273
|
{
|
|
268
|
-
const children =
|
|
274
|
+
const children = isEmpty(nodes) ? [createBlock('paragraph')] : nodes;
|
|
269
275
|
return createBlock(typeMap[node.type], children);
|
|
270
276
|
}
|
|
271
277
|
|
|
@@ -277,7 +283,7 @@ export default function remarkToSlate({
|
|
|
277
283
|
*/
|
|
278
284
|
case 'listItem':
|
|
279
285
|
{
|
|
280
|
-
const children =
|
|
286
|
+
const children = isEmpty(nodes) ? [createBlock('paragraph')] : nodes;
|
|
281
287
|
return createBlock(typeMap[node.type], children);
|
|
282
288
|
}
|
|
283
289
|
|
|
@@ -291,10 +297,11 @@ export default function remarkToSlate({
|
|
|
291
297
|
case 'shortcode':
|
|
292
298
|
{
|
|
293
299
|
const nodes = [createText('')];
|
|
294
|
-
const data =
|
|
300
|
+
const data = {
|
|
301
|
+
...node.data,
|
|
295
302
|
id: node.data.shortcode,
|
|
296
303
|
shortcodeNew: true
|
|
297
|
-
}
|
|
304
|
+
};
|
|
298
305
|
return createBlock(typeMap[node.type], nodes, {
|
|
299
306
|
data
|
|
300
307
|
});
|
|
@@ -387,17 +394,17 @@ export default function remarkToSlate({
|
|
|
387
394
|
*/
|
|
388
395
|
case 'code':
|
|
389
396
|
{
|
|
390
|
-
const data =
|
|
391
|
-
lang: node.lang
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
397
|
+
const data = {
|
|
398
|
+
lang: node.lang,
|
|
399
|
+
...(voidCodeBlock ? {
|
|
400
|
+
code: node.value
|
|
401
|
+
} : {}),
|
|
395
402
|
shortcode: 'code-block',
|
|
396
403
|
shortcodeData: {
|
|
397
404
|
code: node.value,
|
|
398
405
|
lang: node.lang
|
|
399
406
|
}
|
|
400
|
-
}
|
|
407
|
+
};
|
|
401
408
|
const text = createText(voidCodeBlock ? '' : node.value);
|
|
402
409
|
const nodes = [text];
|
|
403
410
|
const block = createBlock('shortcode', nodes, {
|
|
@@ -465,10 +472,11 @@ export default function remarkToSlate({
|
|
|
465
472
|
url,
|
|
466
473
|
data
|
|
467
474
|
} = node;
|
|
468
|
-
const newData =
|
|
475
|
+
const newData = {
|
|
476
|
+
...data,
|
|
469
477
|
title,
|
|
470
478
|
url
|
|
471
|
-
}
|
|
479
|
+
};
|
|
472
480
|
return createInline(typeMap[node.type], {
|
|
473
481
|
data: newData
|
|
474
482
|
}, nodes);
|
|
@@ -489,11 +497,12 @@ export default function remarkToSlate({
|
|
|
489
497
|
alt,
|
|
490
498
|
data
|
|
491
499
|
} = node;
|
|
492
|
-
const newData =
|
|
500
|
+
const newData = {
|
|
501
|
+
...data,
|
|
493
502
|
title,
|
|
494
503
|
alt,
|
|
495
504
|
url
|
|
496
|
-
}
|
|
505
|
+
};
|
|
497
506
|
return createInline(typeMap[node.type], {
|
|
498
507
|
data: newData
|
|
499
508
|
});
|
|
@@ -1,10 +1,5 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
4
|
-
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
5
|
-
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
6
|
-
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : String(i); }
|
|
7
|
-
function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
1
|
+
import without from 'lodash/without';
|
|
2
|
+
import flatten from 'lodash/flatten';
|
|
8
3
|
import u from 'unist-builder';
|
|
9
4
|
import mdastDefinitions from 'mdast-util-definitions';
|
|
10
5
|
|
|
@@ -74,9 +69,10 @@ export default function remarkSquashReferences() {
|
|
|
74
69
|
if (node.type === 'definition') {
|
|
75
70
|
return null;
|
|
76
71
|
}
|
|
77
|
-
const filteredChildren =
|
|
78
|
-
return
|
|
79
|
-
|
|
80
|
-
|
|
72
|
+
const filteredChildren = without(children, null);
|
|
73
|
+
return {
|
|
74
|
+
...node,
|
|
75
|
+
children: flatten(filteredChildren)
|
|
76
|
+
};
|
|
81
77
|
}
|
|
82
78
|
}
|
|
@@ -1,18 +1,9 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
import
|
|
7
|
-
const _excluded = ["lang", "code"],
|
|
8
|
-
_excluded2 = ["url", "title", "alt"];
|
|
9
|
-
function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
|
|
10
|
-
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
|
|
11
|
-
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
12
|
-
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
13
|
-
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
14
|
-
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : String(i); }
|
|
15
|
-
function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
1
|
+
import get from 'lodash/get';
|
|
2
|
+
import without from 'lodash/without';
|
|
3
|
+
import last from 'lodash/last';
|
|
4
|
+
import map from 'lodash/map';
|
|
5
|
+
import intersection from 'lodash/intersection';
|
|
6
|
+
import omit from 'lodash/omit';
|
|
16
7
|
import u from 'unist-builder';
|
|
17
8
|
import mdastToString from 'mdast-util-to-string';
|
|
18
9
|
|
|
@@ -88,22 +79,26 @@ export default function slateToRemark(value, {
|
|
|
88
79
|
}
|
|
89
80
|
function removeMarkFromNodes(nodes, markType) {
|
|
90
81
|
return nodes.map(node => {
|
|
91
|
-
const newNode =
|
|
82
|
+
const newNode = {
|
|
83
|
+
...node
|
|
84
|
+
};
|
|
92
85
|
switch (node.type) {
|
|
93
86
|
case 'link':
|
|
94
87
|
{
|
|
95
88
|
const updatedNodes = removeMarkFromNodes(node.children, markType);
|
|
96
|
-
return
|
|
89
|
+
return {
|
|
90
|
+
...node,
|
|
97
91
|
children: updatedNodes
|
|
98
|
-
}
|
|
92
|
+
};
|
|
99
93
|
}
|
|
100
94
|
case 'image':
|
|
101
95
|
case 'break':
|
|
102
96
|
{
|
|
103
|
-
const data =
|
|
104
|
-
return
|
|
97
|
+
const data = omit(node.data, 'marks');
|
|
98
|
+
return {
|
|
99
|
+
...node,
|
|
105
100
|
data
|
|
106
|
-
}
|
|
101
|
+
};
|
|
107
102
|
}
|
|
108
103
|
default:
|
|
109
104
|
delete newNode[markType];
|
|
@@ -127,18 +122,20 @@ export default function slateToRemark(value, {
|
|
|
127
122
|
// that, like when they wrap all of the text content of a link. Here we
|
|
128
123
|
// remove code marks before processing so that they stay put.
|
|
129
124
|
const nodesWithoutCode = node.children.map(n => {
|
|
130
|
-
const newNode =
|
|
125
|
+
const newNode = {
|
|
126
|
+
...n
|
|
127
|
+
};
|
|
131
128
|
newNode.marks = n.marks ? n.marks.filter(({
|
|
132
129
|
type
|
|
133
130
|
}) => type !== 'code') : n.marks, delete newNode.code;
|
|
134
131
|
return newNode;
|
|
135
132
|
});
|
|
136
|
-
const childMarks =
|
|
137
|
-
return
|
|
133
|
+
const childMarks = map(nodesWithoutCode, getNodeMarks);
|
|
134
|
+
return intersection(...childMarks);
|
|
138
135
|
}
|
|
139
136
|
case 'break':
|
|
140
137
|
case 'image':
|
|
141
|
-
return
|
|
138
|
+
return map(get(node, ['data', 'marks']), mark => mark.type);
|
|
142
139
|
default:
|
|
143
140
|
return getNodeMarkArray(node);
|
|
144
141
|
}
|
|
@@ -148,7 +145,7 @@ export default function slateToRemark(value, {
|
|
|
148
145
|
}
|
|
149
146
|
function getSharedMarks(marks, node) {
|
|
150
147
|
const nodeMarks = getNodeMarks(node);
|
|
151
|
-
const sharedMarks =
|
|
148
|
+
const sharedMarks = intersection(marks, nodeMarks);
|
|
152
149
|
if (sharedMarks[0] === 'code') {
|
|
153
150
|
return nodeMarks.length === 1 ? marks : [];
|
|
154
151
|
}
|
|
@@ -161,7 +158,7 @@ export default function slateToRemark(value, {
|
|
|
161
158
|
// If only the code mark is present, don't allow it to be shared with other
|
|
162
159
|
// nodes.
|
|
163
160
|
if (firstGroupMarks[0] === 'code' && firstGroupMarks.length > 1) {
|
|
164
|
-
firstGroupMarks = [...
|
|
161
|
+
firstGroupMarks = [...without('firstGroupMarks', 'code'), 'code'];
|
|
165
162
|
}
|
|
166
163
|
let splitIndex = 1;
|
|
167
164
|
if (firstGroupMarks.length > 0) {
|
|
@@ -205,9 +202,10 @@ export default function slateToRemark(value, {
|
|
|
205
202
|
const text = trailing ? firstSplit : secondSplit;
|
|
206
203
|
return {
|
|
207
204
|
whitespace,
|
|
208
|
-
trimmedNode:
|
|
205
|
+
trimmedNode: {
|
|
206
|
+
...node,
|
|
209
207
|
text
|
|
210
|
-
}
|
|
208
|
+
}
|
|
211
209
|
};
|
|
212
210
|
}
|
|
213
211
|
return {
|
|
@@ -231,7 +229,7 @@ export default function slateToRemark(value, {
|
|
|
231
229
|
whitespace: leadingWhitespace,
|
|
232
230
|
trimmedNode: leadingNode
|
|
233
231
|
} = splitWhitespace(nodes[0]);
|
|
234
|
-
const lastNode = nodes.length > 1 ?
|
|
232
|
+
const lastNode = nodes.length > 1 ? last(nodes) : leadingNode;
|
|
235
233
|
const trailingSplitResult = splitWhitespace(lastNode, {
|
|
236
234
|
trailing: true
|
|
237
235
|
});
|
|
@@ -301,10 +299,14 @@ export default function slateToRemark(value, {
|
|
|
301
299
|
return convertedNodes;
|
|
302
300
|
}
|
|
303
301
|
function convertCodeBlock(node) {
|
|
304
|
-
return
|
|
302
|
+
return {
|
|
303
|
+
...node,
|
|
305
304
|
type: 'code-block',
|
|
306
|
-
data:
|
|
307
|
-
|
|
305
|
+
data: {
|
|
306
|
+
...node.data,
|
|
307
|
+
...node.data.shortcodeData
|
|
308
|
+
}
|
|
309
|
+
};
|
|
308
310
|
}
|
|
309
311
|
function convertBlockNode(node, children) {
|
|
310
312
|
if (node.type == 'shortcode' && node.data.shortcode == 'code-block') {
|
|
@@ -405,14 +407,12 @@ export default function slateToRemark(value, {
|
|
|
405
407
|
*/
|
|
406
408
|
case 'code-block':
|
|
407
409
|
{
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
data = _objectWithoutProperties(_get2, _excluded);
|
|
415
|
-
const value = voidCodeBlock ? code : (_children$ = children[0]) === null || _children$ === void 0 ? void 0 : _children$.value;
|
|
410
|
+
const {
|
|
411
|
+
lang,
|
|
412
|
+
code,
|
|
413
|
+
...data
|
|
414
|
+
} = get(node, 'data', {});
|
|
415
|
+
const value = voidCodeBlock ? code : children[0]?.value;
|
|
416
416
|
return u(typeMap[node.type], {
|
|
417
417
|
lang,
|
|
418
418
|
data
|
|
@@ -434,7 +434,7 @@ export default function slateToRemark(value, {
|
|
|
434
434
|
const ordered = node.type === 'numbered-list';
|
|
435
435
|
const props = {
|
|
436
436
|
ordered,
|
|
437
|
-
start:
|
|
437
|
+
start: get(node.data, 'start') || 1
|
|
438
438
|
};
|
|
439
439
|
return u(typeMap[node.type], props, children);
|
|
440
440
|
}
|
|
@@ -473,10 +473,11 @@ export default function slateToRemark(value, {
|
|
|
473
473
|
title,
|
|
474
474
|
data
|
|
475
475
|
} = node;
|
|
476
|
-
return u(typeMap[node.type],
|
|
476
|
+
return u(typeMap[node.type], {
|
|
477
477
|
url: node.url,
|
|
478
|
-
title
|
|
479
|
-
|
|
478
|
+
title,
|
|
479
|
+
...data
|
|
480
|
+
}, children);
|
|
480
481
|
}
|
|
481
482
|
|
|
482
483
|
/**
|
|
@@ -487,13 +488,12 @@ export default function slateToRemark(value, {
|
|
|
487
488
|
*/
|
|
488
489
|
case 'image':
|
|
489
490
|
{
|
|
490
|
-
const
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
data = _objectWithoutProperties(_get3, _excluded2);
|
|
491
|
+
const {
|
|
492
|
+
url,
|
|
493
|
+
title,
|
|
494
|
+
alt,
|
|
495
|
+
...data
|
|
496
|
+
} = get(node, 'data', {});
|
|
497
497
|
return u(typeMap[node.type], {
|
|
498
498
|
url,
|
|
499
499
|
title,
|