decap-cms-widget-markdown 3.2.0 → 3.3.0
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 +4 -4
- package/dist/decap-cms-widget-markdown.js.map +1 -1
- package/dist/esm/MarkdownControl/RawEditor.js +36 -43
- package/dist/esm/MarkdownControl/Toolbar.js +52 -59
- package/dist/esm/MarkdownControl/ToolbarButton.js +16 -23
- package/dist/esm/MarkdownControl/VisualEditor.js +85 -92
- package/dist/esm/MarkdownControl/components/Shortcode.js +24 -31
- package/dist/esm/MarkdownControl/components/VoidBlock.js +18 -23
- package/dist/esm/MarkdownControl/index.js +30 -35
- package/dist/esm/MarkdownControl/plugins/BreakToDefaultBlock.js +3 -10
- package/dist/esm/MarkdownControl/plugins/CloseBlock.js +3 -10
- package/dist/esm/MarkdownControl/plugins/CommandsAndQueries.js +8 -15
- package/dist/esm/MarkdownControl/plugins/ForceInsert.js +1 -7
- package/dist/esm/MarkdownControl/plugins/Hotkey.js +4 -11
- package/dist/esm/MarkdownControl/plugins/LineBreak.js +3 -10
- package/dist/esm/MarkdownControl/plugins/Link.js +1 -7
- package/dist/esm/MarkdownControl/plugins/blocks/defaultEmptyBlock.js +1 -7
- package/dist/esm/MarkdownControl/plugins/blocks/events/keyDown.js +18 -25
- package/dist/esm/MarkdownControl/plugins/blocks/events/keyDownBackspace.js +11 -18
- package/dist/esm/MarkdownControl/plugins/blocks/events/keyDownEnter.js +9 -16
- package/dist/esm/MarkdownControl/plugins/blocks/events/toggleBlock.js +11 -18
- package/dist/esm/MarkdownControl/plugins/blocks/locations/areCurrentAndPreviousBlocksOfType.js +5 -12
- package/dist/esm/MarkdownControl/plugins/blocks/locations/getListTypeAtCursor.js +4 -11
- package/dist/esm/MarkdownControl/plugins/blocks/locations/isCursorAtEndOfParagraph.js +5 -12
- package/dist/esm/MarkdownControl/plugins/blocks/locations/isCursorAtStartOfBlockType.js +5 -12
- package/dist/esm/MarkdownControl/plugins/blocks/locations/isCursorAtStartOfNonEmptyHeading.js +5 -11
- package/dist/esm/MarkdownControl/plugins/blocks/locations/isCursorCollapsedAfterSoftBreak.js +4 -10
- package/dist/esm/MarkdownControl/plugins/blocks/locations/isCursorInBlockType.js +4 -10
- package/dist/esm/MarkdownControl/plugins/blocks/locations/isCursorInNonDefaultBlock.js +5 -11
- package/dist/esm/MarkdownControl/plugins/blocks/transforms/splitIntoParagraph.js +6 -12
- package/dist/esm/MarkdownControl/plugins/blocks/transforms/unwrapIfCursorAtStart.js +12 -19
- package/dist/esm/MarkdownControl/plugins/blocks/transforms/wrapListItemsInBlock.js +7 -13
- package/dist/esm/MarkdownControl/plugins/blocks/withBlocks.js +5 -12
- package/dist/esm/MarkdownControl/plugins/html/withHtml.js +29 -14
- package/dist/esm/MarkdownControl/plugins/inlines/events/keyDown.js +11 -18
- package/dist/esm/MarkdownControl/plugins/inlines/events/keyDownShiftEnter.js +5 -11
- package/dist/esm/MarkdownControl/plugins/inlines/events/toggleLink.js +7 -14
- package/dist/esm/MarkdownControl/plugins/inlines/events/toggleMark.js +6 -13
- package/dist/esm/MarkdownControl/plugins/inlines/locations/isMarkActive.js +3 -9
- package/dist/esm/MarkdownControl/plugins/inlines/selectors/getActiveLink.js +4 -11
- package/dist/esm/MarkdownControl/plugins/inlines/transforms/unwrapLink.js +4 -11
- package/dist/esm/MarkdownControl/plugins/inlines/transforms/wrapLink.js +11 -18
- package/dist/esm/MarkdownControl/plugins/inlines/withInlines.js +3 -10
- package/dist/esm/MarkdownControl/plugins/lists/events/keyDown.js +14 -21
- package/dist/esm/MarkdownControl/plugins/lists/events/keyDownBackspace.js +11 -18
- package/dist/esm/MarkdownControl/plugins/lists/events/keyDownEnter.js +18 -25
- package/dist/esm/MarkdownControl/plugins/lists/events/keyDownShiftTab.js +9 -16
- package/dist/esm/MarkdownControl/plugins/lists/events/keyDownTab.js +13 -20
- package/dist/esm/MarkdownControl/plugins/lists/events/toggleListType.js +11 -18
- package/dist/esm/MarkdownControl/plugins/lists/locations/isCursorAtListItemStart.js +3 -9
- package/dist/esm/MarkdownControl/plugins/lists/locations/isCursorAtNoninitialParagraphStart.js +3 -9
- package/dist/esm/MarkdownControl/plugins/lists/locations/isCursorInItemContainingNestedList.js +3 -10
- package/dist/esm/MarkdownControl/plugins/lists/locations/isCursorInListItem.js +4 -10
- package/dist/esm/MarkdownControl/plugins/lists/locations/isSelectionWithinNoninitialListItem.js +4 -10
- package/dist/esm/MarkdownControl/plugins/lists/selectors/getListContainedInListItem.js +5 -12
- package/dist/esm/MarkdownControl/plugins/lists/selectors/getLowestAncestorList.js +4 -11
- package/dist/esm/MarkdownControl/plugins/lists/selectors/getLowestAncestorQuote.js +4 -11
- package/dist/esm/MarkdownControl/plugins/lists/transforms/changeListType.js +8 -15
- package/dist/esm/MarkdownControl/plugins/lists/transforms/convertParagraphToListItem.js +8 -15
- package/dist/esm/MarkdownControl/plugins/lists/transforms/liftFirstMatchedParent.js +3 -9
- package/dist/esm/MarkdownControl/plugins/lists/transforms/liftListItem.js +13 -20
- package/dist/esm/MarkdownControl/plugins/lists/transforms/mergeWithPreviousListItem.js +6 -13
- package/dist/esm/MarkdownControl/plugins/lists/transforms/moveListToListItem.js +3 -9
- package/dist/esm/MarkdownControl/plugins/lists/transforms/splitListItem.js +12 -19
- package/dist/esm/MarkdownControl/plugins/lists/transforms/splitToNestedList.js +11 -18
- package/dist/esm/MarkdownControl/plugins/lists/transforms/unwrapFirstMatchedParent.js +4 -11
- package/dist/esm/MarkdownControl/plugins/lists/transforms/unwrapSelectionFromList.js +7 -14
- package/dist/esm/MarkdownControl/plugins/lists/transforms/wrapFirstMatchedParent.js +4 -11
- package/dist/esm/MarkdownControl/plugins/lists/transforms/wrapSelectionInList.js +8 -15
- package/dist/esm/MarkdownControl/plugins/lists/withLists.js +19 -26
- package/dist/esm/MarkdownControl/plugins/matchers/lowestMatchedAncestor.js +3 -10
- package/dist/esm/MarkdownControl/plugins/matchers/matchLink.js +3 -9
- package/dist/esm/MarkdownControl/plugins/matchers/matchedAncestors.js +3 -9
- package/dist/esm/MarkdownControl/plugins/shortcodes/insertShortcode.js +6 -13
- package/dist/esm/MarkdownControl/plugins/shortcodes/locations/isCursorInEmptyParagraph.js +5 -11
- package/dist/esm/MarkdownControl/plugins/shortcodes/withShortcodes.js +5 -12
- package/dist/esm/MarkdownControl/plugins/util.js +5 -12
- package/dist/esm/MarkdownControl/renderers.js +84 -91
- package/dist/esm/MarkdownPreview.js +14 -21
- package/dist/esm/index.js +10 -17
- package/dist/esm/regexHelper.js +6 -15
- package/dist/esm/schema.js +1 -7
- package/dist/esm/serializers/index.js +46 -57
- package/dist/esm/serializers/rehypePaperEmoji.js +1 -7
- package/dist/esm/serializers/remarkAllowHtmlEntities.js +1 -7
- package/dist/esm/serializers/remarkAssertParents.js +17 -23
- package/dist/esm/serializers/remarkEscapeMarkdownEntities.js +14 -20
- package/dist/esm/serializers/remarkImagesToText.js +1 -7
- package/dist/esm/serializers/remarkPaddedLinks.js +20 -26
- package/dist/esm/serializers/remarkRehypeShortcodes.js +12 -18
- package/dist/esm/serializers/remarkShortcodes.js +3 -11
- package/dist/esm/serializers/remarkSlate.js +18 -26
- package/dist/esm/serializers/remarkSquashReferences.js +13 -19
- package/dist/esm/serializers/remarkStripTrailingBreaks.js +3 -9
- package/dist/esm/serializers/remarkWrapHtml.js +3 -9
- package/dist/esm/serializers/slateRemark.js +35 -41
- package/dist/esm/styles.js +5 -12
- package/dist/esm/types.js +2 -8
- package/package.json +2 -2
- package/src/MarkdownControl/RawEditor.js +2 -1
- package/src/MarkdownControl/VisualEditor.js +2 -1
- package/src/MarkdownControl/index.js +4 -0
- package/src/MarkdownControl/plugins/html/withHtml.js +19 -0
|
@@ -1,24 +1,18 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
var _trimEnd2 = _interopRequireDefault(require("lodash/trimEnd"));
|
|
9
|
-
var _trimStart2 = _interopRequireDefault(require("lodash/trimStart"));
|
|
10
|
-
var _endsWith2 = _interopRequireDefault(require("lodash/endsWith"));
|
|
11
|
-
var _startsWith2 = _interopRequireDefault(require("lodash/startsWith"));
|
|
12
|
-
var _findLast2 = _interopRequireDefault(require("lodash/findLast"));
|
|
13
|
-
var _find2 = _interopRequireDefault(require("lodash/find"));
|
|
14
|
-
var _unistBuilder = _interopRequireDefault(require("unist-builder"));
|
|
15
|
-
var _mdastUtilToString = _interopRequireDefault(require("mdast-util-to-string"));
|
|
16
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
1
|
+
import _flatMap from "lodash/flatMap";
|
|
2
|
+
import _trimEnd from "lodash/trimEnd";
|
|
3
|
+
import _trimStart from "lodash/trimStart";
|
|
4
|
+
import _endsWith from "lodash/endsWith";
|
|
5
|
+
import _startsWith from "lodash/startsWith";
|
|
6
|
+
import _findLast from "lodash/findLast";
|
|
7
|
+
import _find from "lodash/find";
|
|
17
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; }
|
|
18
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; }
|
|
19
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; }
|
|
20
11
|
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : String(i); }
|
|
21
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); }
|
|
13
|
+
import u from 'unist-builder';
|
|
14
|
+
import toString from 'mdast-util-to-string';
|
|
15
|
+
|
|
22
16
|
/**
|
|
23
17
|
* Convert leading and trailing spaces in a link to single spaces outside of the
|
|
24
18
|
* link. MDASTs derived from pasted Google Docs HTML require this treatment.
|
|
@@ -28,7 +22,7 @@ function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e =
|
|
|
28
22
|
* parent (link) node and its children at once, rather than just processing
|
|
29
23
|
* children one at a time.
|
|
30
24
|
*/
|
|
31
|
-
function remarkPaddedLinks() {
|
|
25
|
+
export default function remarkPaddedLinks() {
|
|
32
26
|
function transform(node) {
|
|
33
27
|
/**
|
|
34
28
|
* Because we're operating on link nodes and their children at once, we can
|
|
@@ -47,7 +41,7 @@ function remarkPaddedLinks() {
|
|
|
47
41
|
* this seems unlikely to produce a noticeable perf gain.
|
|
48
42
|
*/
|
|
49
43
|
const hasLinkChild = node.children.some(child => child.type === 'link');
|
|
50
|
-
const processedChildren = hasLinkChild ? (
|
|
44
|
+
const processedChildren = hasLinkChild ? _flatMap(node.children, transformChildren) : node.children;
|
|
51
45
|
|
|
52
46
|
/**
|
|
53
47
|
* Run all children through the transform recursively.
|
|
@@ -64,9 +58,9 @@ function remarkPaddedLinks() {
|
|
|
64
58
|
* Get the node's complete string value, check for leading and trailing
|
|
65
59
|
* whitespace, and get nodes from each edge where whitespace is found.
|
|
66
60
|
*/
|
|
67
|
-
const text = (
|
|
68
|
-
const leadingWhitespaceNode = (
|
|
69
|
-
const trailingWhitespaceNode = (
|
|
61
|
+
const text = toString(node);
|
|
62
|
+
const leadingWhitespaceNode = _startsWith(text, ' ') && getEdgeTextChild(node);
|
|
63
|
+
const trailingWhitespaceNode = _endsWith(text, ' ') && getEdgeTextChild(node, true);
|
|
70
64
|
if (!leadingWhitespaceNode && !trailingWhitespaceNode) return node;
|
|
71
65
|
|
|
72
66
|
/**
|
|
@@ -75,17 +69,17 @@ function remarkPaddedLinks() {
|
|
|
75
69
|
* ASTs.
|
|
76
70
|
*/
|
|
77
71
|
if (leadingWhitespaceNode) {
|
|
78
|
-
leadingWhitespaceNode.value = (
|
|
72
|
+
leadingWhitespaceNode.value = _trimStart(leadingWhitespaceNode.value);
|
|
79
73
|
}
|
|
80
74
|
if (trailingWhitespaceNode) {
|
|
81
|
-
trailingWhitespaceNode.value = (
|
|
75
|
+
trailingWhitespaceNode.value = _trimEnd(trailingWhitespaceNode.value);
|
|
82
76
|
}
|
|
83
77
|
|
|
84
78
|
/**
|
|
85
79
|
* Create an array of nodes. The first and last child will either be `false`
|
|
86
80
|
* or a text node. We filter out the false values before returning.
|
|
87
81
|
*/
|
|
88
|
-
const nodes = [leadingWhitespaceNode && (
|
|
82
|
+
const nodes = [leadingWhitespaceNode && u('text', ' '), node, trailingWhitespaceNode && u('text', ' ')];
|
|
89
83
|
return nodes.filter(val => val);
|
|
90
84
|
}
|
|
91
85
|
|
|
@@ -102,9 +96,9 @@ function remarkPaddedLinks() {
|
|
|
102
96
|
*/
|
|
103
97
|
let findFn;
|
|
104
98
|
if (end) {
|
|
105
|
-
findFn =
|
|
99
|
+
findFn = _findLast;
|
|
106
100
|
} else {
|
|
107
|
-
findFn =
|
|
101
|
+
findFn = _find;
|
|
108
102
|
}
|
|
109
103
|
let edgeChildWithValue;
|
|
110
104
|
setEdgeChildWithValue(node);
|
|
@@ -1,34 +1,28 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = remarkToRehypeShortcodes;
|
|
7
|
-
var _has2 = _interopRequireDefault(require("lodash/has"));
|
|
8
|
-
var _map2 = _interopRequireDefault(require("lodash/map"));
|
|
9
|
-
var _react = _interopRequireDefault(require("react"));
|
|
10
|
-
var _server = require("react-dom/server");
|
|
11
|
-
var _unistBuilder = _interopRequireDefault(require("unist-builder"));
|
|
12
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
1
|
+
import _has from "lodash/has";
|
|
2
|
+
import _map from "lodash/map";
|
|
13
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; }
|
|
14
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; }
|
|
15
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; }
|
|
16
6
|
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : String(i); }
|
|
17
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
|
+
import React from 'react';
|
|
9
|
+
import { renderToString } from 'react-dom/server';
|
|
10
|
+
import u from 'unist-builder';
|
|
11
|
+
|
|
18
12
|
/**
|
|
19
13
|
* This plugin doesn't actually transform Remark (MDAST) nodes to Rehype
|
|
20
14
|
* (HAST) nodes, but rather, it prepares an MDAST shortcode node for HAST
|
|
21
15
|
* conversion by replacing the shortcode text with stringified HTML for
|
|
22
16
|
* previewing the shortcode output.
|
|
23
17
|
*/
|
|
24
|
-
function remarkToRehypeShortcodes({
|
|
18
|
+
export default function remarkToRehypeShortcodes({
|
|
25
19
|
plugins,
|
|
26
20
|
getAsset,
|
|
27
21
|
resolveWidget
|
|
28
22
|
}) {
|
|
29
23
|
return transform;
|
|
30
24
|
function transform(root) {
|
|
31
|
-
const transformedChildren = (
|
|
25
|
+
const transformedChildren = _map(root.children, processShortcodes);
|
|
32
26
|
return _objectSpread(_objectSpread({}, root), {}, {
|
|
33
27
|
children: transformedChildren
|
|
34
28
|
});
|
|
@@ -41,7 +35,7 @@ function remarkToRehypeShortcodes({
|
|
|
41
35
|
/**
|
|
42
36
|
* If the node doesn't contain shortcode data, return the original node.
|
|
43
37
|
*/
|
|
44
|
-
if (!(
|
|
38
|
+
if (!_has(node, ['data', 'shortcode'])) return node;
|
|
45
39
|
|
|
46
40
|
/**
|
|
47
41
|
* Get shortcode data from the node, and retrieve the matching plugin by
|
|
@@ -59,12 +53,12 @@ function remarkToRehypeShortcodes({
|
|
|
59
53
|
* render it to an HTML string.
|
|
60
54
|
*/
|
|
61
55
|
const value = getPreview(plugin, shortcodeData);
|
|
62
|
-
const valueHtml = typeof value === 'string' ? value :
|
|
56
|
+
const valueHtml = typeof value === 'string' ? value : renderToString(value);
|
|
63
57
|
|
|
64
58
|
/**
|
|
65
59
|
* Return a new 'html' type node containing the shortcode preview markup.
|
|
66
60
|
*/
|
|
67
|
-
const textNode = (
|
|
61
|
+
const textNode = u('html', valueHtml);
|
|
68
62
|
const children = [textNode];
|
|
69
63
|
return _objectSpread(_objectSpread({}, node), {}, {
|
|
70
64
|
children
|
|
@@ -84,7 +78,7 @@ function remarkToRehypeShortcodes({
|
|
|
84
78
|
return toPreview(shortcodeData, getAsset, fields);
|
|
85
79
|
}
|
|
86
80
|
const preview = resolveWidget(widget);
|
|
87
|
-
return /*#__PURE__*/
|
|
81
|
+
return /*#__PURE__*/React.createElement(preview.preview, {
|
|
88
82
|
value: shortcodeData,
|
|
89
83
|
field: plugin,
|
|
90
84
|
getAsset
|
|
@@ -1,12 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.createRemarkShortcodeStringifier = createRemarkShortcodeStringifier;
|
|
7
|
-
exports.getLinesWithOffsets = getLinesWithOffsets;
|
|
8
|
-
exports.remarkParseShortcodes = remarkParseShortcodes;
|
|
9
|
-
function remarkParseShortcodes({
|
|
1
|
+
export function remarkParseShortcodes({
|
|
10
2
|
plugins
|
|
11
3
|
}) {
|
|
12
4
|
const Parser = this.Parser;
|
|
@@ -17,7 +9,7 @@ function remarkParseShortcodes({
|
|
|
17
9
|
});
|
|
18
10
|
methods.unshift('shortcode');
|
|
19
11
|
}
|
|
20
|
-
function getLinesWithOffsets(value) {
|
|
12
|
+
export function getLinesWithOffsets(value) {
|
|
21
13
|
const SEPARATOR = '\n\n';
|
|
22
14
|
const splitted = value.split(SEPARATOR);
|
|
23
15
|
const trimmedLines = splitted.reduce((acc, line) => {
|
|
@@ -105,7 +97,7 @@ function createShortcodeTokenizer({
|
|
|
105
97
|
}
|
|
106
98
|
};
|
|
107
99
|
}
|
|
108
|
-
function createRemarkShortcodeStringifier({
|
|
100
|
+
export function createRemarkShortcodeStringifier({
|
|
109
101
|
plugins
|
|
110
102
|
}) {
|
|
111
103
|
return function remarkStringifyShortcodes() {
|
|
@@ -1,17 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
exports.mergeAdjacentTexts = mergeAdjacentTexts;
|
|
8
|
-
var _isEqual2 = _interopRequireDefault(require("lodash/isEqual"));
|
|
9
|
-
var _flatten2 = _interopRequireDefault(require("lodash/flatten"));
|
|
10
|
-
var _map2 = _interopRequireDefault(require("lodash/map"));
|
|
11
|
-
var _flatMap2 = _interopRequireDefault(require("lodash/flatMap"));
|
|
12
|
-
var _isArray2 = _interopRequireDefault(require("lodash/isArray"));
|
|
13
|
-
var _isEmpty2 = _interopRequireDefault(require("lodash/isEmpty"));
|
|
14
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
1
|
+
import _isEqual from "lodash/isEqual";
|
|
2
|
+
import _flatten from "lodash/flatten";
|
|
3
|
+
import _map from "lodash/map";
|
|
4
|
+
import _flatMap from "lodash/flatMap";
|
|
5
|
+
import _isArray from "lodash/isArray";
|
|
6
|
+
import _isEmpty from "lodash/isEmpty";
|
|
15
7
|
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; }
|
|
16
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; }
|
|
17
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; }
|
|
@@ -48,9 +40,9 @@ function isText(node) {
|
|
|
48
40
|
return !!node.text;
|
|
49
41
|
}
|
|
50
42
|
function isMarksEqual(node1, node2) {
|
|
51
|
-
return (
|
|
43
|
+
return _isEqual(node1.marks, node2.marks);
|
|
52
44
|
}
|
|
53
|
-
function mergeAdjacentTexts(children) {
|
|
45
|
+
export function mergeAdjacentTexts(children) {
|
|
54
46
|
if (children.length <= 0) {
|
|
55
47
|
return children;
|
|
56
48
|
}
|
|
@@ -84,7 +76,7 @@ function mergeAdjacentTexts(children) {
|
|
|
84
76
|
* A Remark plugin for converting an MDAST to Slate Raw AST. Remark plugins
|
|
85
77
|
* return a `transformNode` function that receives the MDAST as it's first argument.
|
|
86
78
|
*/
|
|
87
|
-
function remarkToSlate({
|
|
79
|
+
export default function remarkToSlate({
|
|
88
80
|
voidCodeBlock
|
|
89
81
|
} = {}) {
|
|
90
82
|
return transformNode;
|
|
@@ -96,7 +88,7 @@ function remarkToSlate({
|
|
|
96
88
|
* translate from MDAST to Slate, such as definitions for link/image
|
|
97
89
|
* references or footnotes.
|
|
98
90
|
*/
|
|
99
|
-
let children = !['strong', 'emphasis', 'delete'].includes(node.type) && !(
|
|
91
|
+
let children = !['strong', 'emphasis', 'delete'].includes(node.type) && !_isEmpty(node.children) && _flatMap(node.children, transformNode).filter(val => val);
|
|
100
92
|
if (Array.isArray(children)) {
|
|
101
93
|
// Merge adjacent text nodes with the same marks to conform to slate schema
|
|
102
94
|
children = mergeAdjacentTexts(children);
|
|
@@ -122,13 +114,13 @@ function remarkToSlate({
|
|
|
122
114
|
* Create a Slate Block node.
|
|
123
115
|
*/
|
|
124
116
|
function createBlock(type, nodes, props = {}) {
|
|
125
|
-
if (!(
|
|
117
|
+
if (!_isArray(nodes)) {
|
|
126
118
|
props = nodes;
|
|
127
119
|
nodes = undefined;
|
|
128
120
|
}
|
|
129
121
|
|
|
130
122
|
// Ensure block nodes have at least one text child to conform to slate schema
|
|
131
|
-
const children = (
|
|
123
|
+
const children = _isEmpty(nodes) ? [createText('')] : nodes;
|
|
132
124
|
const node = _objectSpread({
|
|
133
125
|
type
|
|
134
126
|
}, props);
|
|
@@ -144,7 +136,7 @@ function remarkToSlate({
|
|
|
144
136
|
}, props);
|
|
145
137
|
|
|
146
138
|
// Ensure inline nodes have at least one text child to conform to slate schema
|
|
147
|
-
const children = (
|
|
139
|
+
const children = _isEmpty(nodes) ? [createText('')] : nodes;
|
|
148
140
|
return addNodes(node, children);
|
|
149
141
|
}
|
|
150
142
|
|
|
@@ -206,8 +198,8 @@ function remarkToSlate({
|
|
|
206
198
|
return processMarkNode(childNode, marks);
|
|
207
199
|
case 'link':
|
|
208
200
|
{
|
|
209
|
-
const nodes = (
|
|
210
|
-
const result = convertNode(childNode, (
|
|
201
|
+
const nodes = _map(childNode.children, child => normalizeMarks(processMarkChild(child, marks)));
|
|
202
|
+
const result = convertNode(childNode, _flatten(nodes));
|
|
211
203
|
return result;
|
|
212
204
|
}
|
|
213
205
|
|
|
@@ -234,7 +226,7 @@ function remarkToSlate({
|
|
|
234
226
|
}) => type !== markType), {
|
|
235
227
|
type: markType
|
|
236
228
|
}] : parentMarks;
|
|
237
|
-
const children = (
|
|
229
|
+
const children = _flatMap(node.children, child => normalizeMarks(processMarkChild(child, marks)));
|
|
238
230
|
return children;
|
|
239
231
|
}
|
|
240
232
|
function normalizeMarks(node) {
|
|
@@ -273,7 +265,7 @@ function remarkToSlate({
|
|
|
273
265
|
*/
|
|
274
266
|
case 'root':
|
|
275
267
|
{
|
|
276
|
-
const children = (
|
|
268
|
+
const children = _isEmpty(nodes) ? [createBlock('paragraph')] : nodes;
|
|
277
269
|
return createBlock(typeMap[node.type], children);
|
|
278
270
|
}
|
|
279
271
|
|
|
@@ -285,7 +277,7 @@ function remarkToSlate({
|
|
|
285
277
|
*/
|
|
286
278
|
case 'listItem':
|
|
287
279
|
{
|
|
288
|
-
const children = (
|
|
280
|
+
const children = _isEmpty(nodes) ? [createBlock('paragraph')] : nodes;
|
|
289
281
|
return createBlock(typeMap[node.type], children);
|
|
290
282
|
}
|
|
291
283
|
|
|
@@ -1,19 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = remarkSquashReferences;
|
|
7
|
-
var _flatten2 = _interopRequireDefault(require("lodash/flatten"));
|
|
8
|
-
var _without2 = _interopRequireDefault(require("lodash/without"));
|
|
9
|
-
var _unistBuilder = _interopRequireDefault(require("unist-builder"));
|
|
10
|
-
var _mdastUtilDefinitions = _interopRequireDefault(require("mdast-util-definitions"));
|
|
11
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
1
|
+
import _flatten from "lodash/flatten";
|
|
2
|
+
import _without from "lodash/without";
|
|
12
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; }
|
|
13
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; }
|
|
14
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; }
|
|
15
6
|
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : String(i); }
|
|
16
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
|
+
import u from 'unist-builder';
|
|
9
|
+
import mdastDefinitions from 'mdast-util-definitions';
|
|
10
|
+
|
|
17
11
|
/**
|
|
18
12
|
* Raw markdown may contain image references or link references. Because there
|
|
19
13
|
* is no way to maintain these references within the Slate AST, we convert image
|
|
@@ -35,10 +29,10 @@ function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e =
|
|
|
35
29
|
* ```
|
|
36
30
|
*
|
|
37
31
|
*/
|
|
38
|
-
function remarkSquashReferences() {
|
|
32
|
+
export default function remarkSquashReferences() {
|
|
39
33
|
return getTransform;
|
|
40
34
|
function getTransform(node) {
|
|
41
|
-
const getDefinition = (
|
|
35
|
+
const getDefinition = mdastDefinitions(node);
|
|
42
36
|
return transform.call(null, getDefinition, node);
|
|
43
37
|
}
|
|
44
38
|
function transform(getDefinition, node) {
|
|
@@ -61,15 +55,15 @@ function remarkSquashReferences() {
|
|
|
61
55
|
title,
|
|
62
56
|
url
|
|
63
57
|
} = definition;
|
|
64
|
-
return (
|
|
58
|
+
return u(type, {
|
|
65
59
|
title,
|
|
66
60
|
url,
|
|
67
61
|
alt: node.alt
|
|
68
62
|
}, children);
|
|
69
63
|
}
|
|
70
|
-
const pre = (
|
|
71
|
-
const post = (
|
|
72
|
-
const nodes = children || [(
|
|
64
|
+
const pre = u('text', node.type === 'imageReference' ? '![' : '[');
|
|
65
|
+
const post = u('text', ']');
|
|
66
|
+
const nodes = children || [u('text', node.alt)];
|
|
73
67
|
return [pre, ...nodes, post];
|
|
74
68
|
}
|
|
75
69
|
|
|
@@ -80,9 +74,9 @@ function remarkSquashReferences() {
|
|
|
80
74
|
if (node.type === 'definition') {
|
|
81
75
|
return null;
|
|
82
76
|
}
|
|
83
|
-
const filteredChildren = (
|
|
77
|
+
const filteredChildren = _without(children, null);
|
|
84
78
|
return _objectSpread(_objectSpread({}, node), {}, {
|
|
85
|
-
children: (
|
|
79
|
+
children: _flatten(filteredChildren)
|
|
86
80
|
});
|
|
87
81
|
}
|
|
88
82
|
}
|
|
@@ -1,11 +1,5 @@
|
|
|
1
|
-
|
|
1
|
+
import mdastToString from 'mdast-util-to-string';
|
|
2
2
|
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = remarkStripTrailingBreaks;
|
|
7
|
-
var _mdastUtilToString = _interopRequireDefault(require("mdast-util-to-string"));
|
|
8
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
9
3
|
/**
|
|
10
4
|
* Removes break nodes that are at the end of a block.
|
|
11
5
|
*
|
|
@@ -15,7 +9,7 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
|
|
|
15
9
|
* however, may have such entities, and users of visual editors shouldn't see
|
|
16
10
|
* these artifacts in resulting markdown.
|
|
17
11
|
*/
|
|
18
|
-
function remarkStripTrailingBreaks() {
|
|
12
|
+
export default function remarkStripTrailingBreaks() {
|
|
19
13
|
function transform(node) {
|
|
20
14
|
if (node.children) {
|
|
21
15
|
node.children = node.children.map((child, idx, children) => {
|
|
@@ -36,7 +30,7 @@ function remarkStripTrailingBreaks() {
|
|
|
36
30
|
type: 'root',
|
|
37
31
|
children: subsequentNodes
|
|
38
32
|
};
|
|
39
|
-
const subsequentText = (
|
|
33
|
+
const subsequentText = mdastToString(fragment);
|
|
40
34
|
return subsequentText.trim() ? child : null;
|
|
41
35
|
}
|
|
42
36
|
|
|
@@ -1,20 +1,14 @@
|
|
|
1
|
-
|
|
1
|
+
import u from 'unist-builder';
|
|
2
2
|
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = remarkWrapHtml;
|
|
7
|
-
var _unistBuilder = _interopRequireDefault(require("unist-builder"));
|
|
8
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
9
3
|
/**
|
|
10
4
|
* Ensure that top level 'html' type nodes are wrapped in paragraphs. Html nodes
|
|
11
5
|
* are used for text nodes that we don't want Remark or Rehype to parse.
|
|
12
6
|
*/
|
|
13
|
-
function remarkWrapHtml() {
|
|
7
|
+
export default function remarkWrapHtml() {
|
|
14
8
|
function transform(tree) {
|
|
15
9
|
tree.children = tree.children.map(node => {
|
|
16
10
|
if (node.type === 'html') {
|
|
17
|
-
return (
|
|
11
|
+
return u('paragraph', [node]);
|
|
18
12
|
}
|
|
19
13
|
return node;
|
|
20
14
|
});
|