decap-cms-widget-markdown 2.16.0-beta.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 +820 -0
- package/LICENSE +22 -0
- package/README.md +9 -0
- package/dist/decap-cms-widget-markdown.js +9 -0
- package/dist/decap-cms-widget-markdown.js.LICENSE.txt +37 -0
- package/dist/decap-cms-widget-markdown.js.map +1 -0
- package/dist/esm/MarkdownControl/RawEditor.js +106 -0
- package/dist/esm/MarkdownControl/Toolbar.js +216 -0
- package/dist/esm/MarkdownControl/ToolbarButton.js +43 -0
- package/dist/esm/MarkdownControl/VisualEditor.js +268 -0
- package/dist/esm/MarkdownControl/components/Shortcode.js +78 -0
- package/dist/esm/MarkdownControl/components/VoidBlock.js +55 -0
- package/dist/esm/MarkdownControl/index.js +129 -0
- package/dist/esm/MarkdownControl/plugins/BreakToDefaultBlock.js +34 -0
- package/dist/esm/MarkdownControl/plugins/CloseBlock.js +36 -0
- package/dist/esm/MarkdownControl/plugins/CommandsAndQueries.js +188 -0
- package/dist/esm/MarkdownControl/plugins/ForceInsert.js +49 -0
- package/dist/esm/MarkdownControl/plugins/Hotkey.js +35 -0
- package/dist/esm/MarkdownControl/plugins/LineBreak.js +21 -0
- package/dist/esm/MarkdownControl/plugins/Link.js +56 -0
- package/dist/esm/MarkdownControl/plugins/blocks/defaultEmptyBlock.js +16 -0
- package/dist/esm/MarkdownControl/plugins/blocks/events/keyDown.js +47 -0
- package/dist/esm/MarkdownControl/plugins/blocks/events/keyDownBackspace.js +26 -0
- package/dist/esm/MarkdownControl/plugins/blocks/events/keyDownEnter.js +28 -0
- package/dist/esm/MarkdownControl/plugins/blocks/events/toggleBlock.js +46 -0
- package/dist/esm/MarkdownControl/plugins/blocks/locations/areCurrentAndPreviousBlocksOfType.js +20 -0
- package/dist/esm/MarkdownControl/plugins/blocks/locations/getListTypeAtCursor.js +16 -0
- package/dist/esm/MarkdownControl/plugins/blocks/locations/isCursorAtEndOfParagraph.js +19 -0
- package/dist/esm/MarkdownControl/plugins/blocks/locations/isCursorAtStartOfBlockType.js +19 -0
- package/dist/esm/MarkdownControl/plugins/blocks/locations/isCursorAtStartOfNonEmptyHeading.js +20 -0
- package/dist/esm/MarkdownControl/plugins/blocks/locations/isCursorInBlockType.js +20 -0
- package/dist/esm/MarkdownControl/plugins/blocks/locations/isCursorInNonDefaultBlock.js +20 -0
- package/dist/esm/MarkdownControl/plugins/blocks/transforms/splitIntoParagraph.js +23 -0
- package/dist/esm/MarkdownControl/plugins/blocks/transforms/unwrapIfCursorAtStart.js +36 -0
- package/dist/esm/MarkdownControl/plugins/blocks/transforms/wrapListItemsInBlock.js +27 -0
- package/dist/esm/MarkdownControl/plugins/blocks/withBlocks.js +19 -0
- package/dist/esm/MarkdownControl/plugins/inlines/events/keyDown.js +39 -0
- package/dist/esm/MarkdownControl/plugins/inlines/events/keyDownShiftEnter.js +27 -0
- package/dist/esm/MarkdownControl/plugins/inlines/events/toggleLink.js +24 -0
- package/dist/esm/MarkdownControl/plugins/inlines/events/toggleMark.js +18 -0
- package/dist/esm/MarkdownControl/plugins/inlines/locations/isMarkActive.js +17 -0
- package/dist/esm/MarkdownControl/plugins/inlines/selectors/getActiveLink.js +15 -0
- package/dist/esm/MarkdownControl/plugins/inlines/transforms/unwrapLink.js +14 -0
- package/dist/esm/MarkdownControl/plugins/inlines/transforms/wrapLink.js +45 -0
- package/dist/esm/MarkdownControl/plugins/inlines/withInlines.js +23 -0
- package/dist/esm/MarkdownControl/plugins/lists/events/keyDown.js +38 -0
- package/dist/esm/MarkdownControl/plugins/lists/events/keyDownBackspace.js +29 -0
- package/dist/esm/MarkdownControl/plugins/lists/events/keyDownEnter.js +44 -0
- package/dist/esm/MarkdownControl/plugins/lists/events/keyDownShiftTab.js +32 -0
- package/dist/esm/MarkdownControl/plugins/lists/events/keyDownTab.js +57 -0
- package/dist/esm/MarkdownControl/plugins/lists/events/toggleListType.js +29 -0
- package/dist/esm/MarkdownControl/plugins/lists/locations/isCursorAtListItemStart.js +18 -0
- package/dist/esm/MarkdownControl/plugins/lists/locations/isCursorAtNoninitialParagraphStart.js +17 -0
- package/dist/esm/MarkdownControl/plugins/lists/locations/isCursorInItemContainingNestedList.js +14 -0
- package/dist/esm/MarkdownControl/plugins/lists/locations/isCursorInListItem.js +20 -0
- package/dist/esm/MarkdownControl/plugins/lists/locations/isSelectionWithinNoninitialListItem.js +18 -0
- package/dist/esm/MarkdownControl/plugins/lists/selectors/getListContainedInListItem.js +18 -0
- package/dist/esm/MarkdownControl/plugins/lists/selectors/getLowestAncestorList.js +15 -0
- package/dist/esm/MarkdownControl/plugins/lists/selectors/getLowestAncestorQuote.js +15 -0
- package/dist/esm/MarkdownControl/plugins/lists/transforms/changeListType.js +24 -0
- package/dist/esm/MarkdownControl/plugins/lists/transforms/convertParagraphToListItem.js +27 -0
- package/dist/esm/MarkdownControl/plugins/lists/transforms/liftFirstMatchedParent.js +20 -0
- package/dist/esm/MarkdownControl/plugins/lists/transforms/liftListItem.js +37 -0
- package/dist/esm/MarkdownControl/plugins/lists/transforms/mergeWithPreviousListItem.js +19 -0
- package/dist/esm/MarkdownControl/plugins/lists/transforms/moveListToListItem.js +18 -0
- package/dist/esm/MarkdownControl/plugins/lists/transforms/splitListItem.js +37 -0
- package/dist/esm/MarkdownControl/plugins/lists/transforms/splitToNestedList.js +37 -0
- package/dist/esm/MarkdownControl/plugins/lists/transforms/unwrapFirstMatchedParent.js +14 -0
- package/dist/esm/MarkdownControl/plugins/lists/transforms/unwrapSelectionFromList.js +25 -0
- package/dist/esm/MarkdownControl/plugins/lists/transforms/wrapFirstMatchedParent.js +14 -0
- package/dist/esm/MarkdownControl/plugins/lists/transforms/wrapSelectionInList.js +27 -0
- package/dist/esm/MarkdownControl/plugins/lists/withLists.js +67 -0
- package/dist/esm/MarkdownControl/plugins/matchers/lowestMatchedAncestor.js +13 -0
- package/dist/esm/MarkdownControl/plugins/matchers/matchLink.js +14 -0
- package/dist/esm/MarkdownControl/plugins/matchers/matchedAncestors.js +15 -0
- package/dist/esm/MarkdownControl/plugins/shortcodes/insertShortcode.js +35 -0
- package/dist/esm/MarkdownControl/plugins/shortcodes/locations/isCursorInEmptyParagraph.js +20 -0
- package/dist/esm/MarkdownControl/plugins/shortcodes/withShortcodes.js +30 -0
- package/dist/esm/MarkdownControl/plugins/util.js +18 -0
- package/dist/esm/MarkdownControl/renderers.js +326 -0
- package/dist/esm/MarkdownPreview.js +47 -0
- package/dist/esm/index.js +31 -0
- package/dist/esm/regexHelper.js +151 -0
- package/dist/esm/schema.js +35 -0
- package/dist/esm/serializers/index.js +233 -0
- package/dist/esm/serializers/rehypePaperEmoji.js +24 -0
- package/dist/esm/serializers/remarkAllowHtmlEntities.js +55 -0
- package/dist/esm/serializers/remarkAssertParents.js +89 -0
- package/dist/esm/serializers/remarkEscapeMarkdownEntities.js +271 -0
- package/dist/esm/serializers/remarkImagesToText.js +41 -0
- package/dist/esm/serializers/remarkPaddedLinks.js +127 -0
- package/dist/esm/serializers/remarkRehypeShortcodes.js +93 -0
- package/dist/esm/serializers/remarkShortcodes.js +123 -0
- package/dist/esm/serializers/remarkSlate.js +518 -0
- package/dist/esm/serializers/remarkSquashReferences.js +88 -0
- package/dist/esm/serializers/remarkStripTrailingBreaks.js +61 -0
- package/dist/esm/serializers/remarkWrapHtml.js +24 -0
- package/dist/esm/serializers/slateRemark.js +512 -0
- package/dist/esm/styles.js +18 -0
- package/dist/esm/types.js +10 -0
- package/package.json +64 -0
- package/src/MarkdownControl/RawEditor.js +100 -0
- package/src/MarkdownControl/Toolbar.js +278 -0
- package/src/MarkdownControl/ToolbarButton.js +48 -0
- package/src/MarkdownControl/VisualEditor.js +293 -0
- package/src/MarkdownControl/__tests__/VisualEditor.spec.js +56 -0
- package/src/MarkdownControl/__tests__/__snapshots__/parser.spec.js.snap +543 -0
- package/src/MarkdownControl/__tests__/parser.spec.js +668 -0
- package/src/MarkdownControl/components/Shortcode.js +74 -0
- package/src/MarkdownControl/components/VoidBlock.js +58 -0
- package/src/MarkdownControl/index.js +125 -0
- package/src/MarkdownControl/plugins/BreakToDefaultBlock.js +23 -0
- package/src/MarkdownControl/plugins/CloseBlock.js +25 -0
- package/src/MarkdownControl/plugins/CommandsAndQueries.js +156 -0
- package/src/MarkdownControl/plugins/ForceInsert.js +38 -0
- package/src/MarkdownControl/plugins/Hotkey.js +29 -0
- package/src/MarkdownControl/plugins/LineBreak.js +15 -0
- package/src/MarkdownControl/plugins/Link.js +40 -0
- package/src/MarkdownControl/plugins/blocks/defaultEmptyBlock.js +8 -0
- package/src/MarkdownControl/plugins/blocks/events/keyDown.js +47 -0
- package/src/MarkdownControl/plugins/blocks/events/keyDownBackspace.js +27 -0
- package/src/MarkdownControl/plugins/blocks/events/keyDownEnter.js +26 -0
- package/src/MarkdownControl/plugins/blocks/events/toggleBlock.js +39 -0
- package/src/MarkdownControl/plugins/blocks/locations/areCurrentAndPreviousBlocksOfType.js +15 -0
- package/src/MarkdownControl/plugins/blocks/locations/getListTypeAtCursor.js +11 -0
- package/src/MarkdownControl/plugins/blocks/locations/isCursorAtEndOfParagraph.js +14 -0
- package/src/MarkdownControl/plugins/blocks/locations/isCursorAtStartOfBlockType.js +14 -0
- package/src/MarkdownControl/plugins/blocks/locations/isCursorAtStartOfNonEmptyHeading.js +22 -0
- package/src/MarkdownControl/plugins/blocks/locations/isCursorInBlockType.js +27 -0
- package/src/MarkdownControl/plugins/blocks/locations/isCursorInNonDefaultBlock.js +17 -0
- package/src/MarkdownControl/plugins/blocks/transforms/splitIntoParagraph.js +13 -0
- package/src/MarkdownControl/plugins/blocks/transforms/unwrapIfCursorAtStart.js +30 -0
- package/src/MarkdownControl/plugins/blocks/transforms/wrapListItemsInBlock.js +11 -0
- package/src/MarkdownControl/plugins/blocks/withBlocks.js +15 -0
- package/src/MarkdownControl/plugins/inlines/events/keyDown.js +38 -0
- package/src/MarkdownControl/plugins/inlines/events/keyDownShiftEnter.js +28 -0
- package/src/MarkdownControl/plugins/inlines/events/toggleLink.js +17 -0
- package/src/MarkdownControl/plugins/inlines/events/toggleMark.js +13 -0
- package/src/MarkdownControl/plugins/inlines/locations/isMarkActive.js +11 -0
- package/src/MarkdownControl/plugins/inlines/selectors/getActiveLink.js +10 -0
- package/src/MarkdownControl/plugins/inlines/transforms/unwrapLink.js +9 -0
- package/src/MarkdownControl/plugins/inlines/transforms/wrapLink.js +30 -0
- package/src/MarkdownControl/plugins/inlines/withInlines.js +20 -0
- package/src/MarkdownControl/plugins/lists/events/keyDown.js +34 -0
- package/src/MarkdownControl/plugins/lists/events/keyDownBackspace.js +31 -0
- package/src/MarkdownControl/plugins/lists/events/keyDownEnter.js +39 -0
- package/src/MarkdownControl/plugins/lists/events/keyDownShiftTab.js +27 -0
- package/src/MarkdownControl/plugins/lists/events/keyDownTab.js +55 -0
- package/src/MarkdownControl/plugins/lists/events/toggleListType.js +23 -0
- package/src/MarkdownControl/plugins/lists/locations/isCursorAtListItemStart.js +13 -0
- package/src/MarkdownControl/plugins/lists/locations/isCursorAtNoninitialParagraphStart.js +11 -0
- package/src/MarkdownControl/plugins/lists/locations/isCursorInItemContainingNestedList.js +9 -0
- package/src/MarkdownControl/plugins/lists/locations/isCursorInListItem.js +21 -0
- package/src/MarkdownControl/plugins/lists/locations/isSelectionWithinNoninitialListItem.js +14 -0
- package/src/MarkdownControl/plugins/lists/selectors/getListContainedInListItem.js +12 -0
- package/src/MarkdownControl/plugins/lists/selectors/getLowestAncestorList.js +11 -0
- package/src/MarkdownControl/plugins/lists/selectors/getLowestAncestorQuote.js +11 -0
- package/src/MarkdownControl/plugins/lists/transforms/changeListType.js +16 -0
- package/src/MarkdownControl/plugins/lists/transforms/convertParagraphToListItem.js +19 -0
- package/src/MarkdownControl/plugins/lists/transforms/liftFirstMatchedParent.js +11 -0
- package/src/MarkdownControl/plugins/lists/transforms/liftListItem.js +30 -0
- package/src/MarkdownControl/plugins/lists/transforms/mergeWithPreviousListItem.js +13 -0
- package/src/MarkdownControl/plugins/lists/transforms/moveListToListItem.js +13 -0
- package/src/MarkdownControl/plugins/lists/transforms/splitListItem.js +33 -0
- package/src/MarkdownControl/plugins/lists/transforms/splitToNestedList.js +33 -0
- package/src/MarkdownControl/plugins/lists/transforms/unwrapFirstMatchedParent.js +9 -0
- package/src/MarkdownControl/plugins/lists/transforms/unwrapSelectionFromList.js +14 -0
- package/src/MarkdownControl/plugins/lists/transforms/wrapFirstMatchedParent.js +9 -0
- package/src/MarkdownControl/plugins/lists/transforms/wrapSelectionInList.js +17 -0
- package/src/MarkdownControl/plugins/lists/withLists.js +66 -0
- package/src/MarkdownControl/plugins/matchers/lowestMatchedAncestor.js +6 -0
- package/src/MarkdownControl/plugins/matchers/matchLink.js +9 -0
- package/src/MarkdownControl/plugins/matchers/matchedAncestors.js +18 -0
- package/src/MarkdownControl/plugins/shortcodes/insertShortcode.js +34 -0
- package/src/MarkdownControl/plugins/shortcodes/locations/isCursorInEmptyParagraph.js +17 -0
- package/src/MarkdownControl/plugins/shortcodes/withShortcodes.js +26 -0
- package/src/MarkdownControl/plugins/util.js +11 -0
- package/src/MarkdownControl/renderers.js +352 -0
- package/src/MarkdownPreview.js +27 -0
- package/src/__tests__/__snapshots__/renderer.spec.js.snap +239 -0
- package/src/__tests__/renderer.spec.js +261 -0
- package/src/index.js +16 -0
- package/src/regexHelper.js +137 -0
- package/src/schema.js +35 -0
- package/src/serializers/__tests__/__fixtures__/commonmarkExpected.json +625 -0
- package/src/serializers/__tests__/__fixtures__/duplicate_marks_github_issue_3280.md +1 -0
- package/src/serializers/__tests__/commonmark.spec.js +110 -0
- package/src/serializers/__tests__/index.spec.js +52 -0
- package/src/serializers/__tests__/remarkAllowHtmlEntities.spec.js +25 -0
- package/src/serializers/__tests__/remarkAssertParents.spec.js +171 -0
- package/src/serializers/__tests__/remarkEscapeMarkdownEntities.spec.js +84 -0
- package/src/serializers/__tests__/remarkPaddedLinks.spec.js +43 -0
- package/src/serializers/__tests__/remarkPlugins.spec.js +299 -0
- package/src/serializers/__tests__/remarkShortcodes.spec.js +106 -0
- package/src/serializers/__tests__/remarkSlate.spec.js +67 -0
- package/src/serializers/__tests__/remarkStripTrailingBreaks.spec.js +23 -0
- package/src/serializers/__tests__/slate.spec.js +300 -0
- package/src/serializers/index.js +226 -0
- package/src/serializers/rehypePaperEmoji.js +16 -0
- package/src/serializers/remarkAllowHtmlEntities.js +58 -0
- package/src/serializers/remarkAssertParents.js +83 -0
- package/src/serializers/remarkEscapeMarkdownEntities.js +269 -0
- package/src/serializers/remarkImagesToText.js +26 -0
- package/src/serializers/remarkPaddedLinks.js +120 -0
- package/src/serializers/remarkRehypeShortcodes.js +67 -0
- package/src/serializers/remarkShortcodes.js +106 -0
- package/src/serializers/remarkSlate.js +425 -0
- package/src/serializers/remarkSquashReferences.js +73 -0
- package/src/serializers/remarkStripTrailingBreaks.js +56 -0
- package/src/serializers/remarkWrapHtml.js +20 -0
- package/src/serializers/slateRemark.js +468 -0
- package/src/styles.js +13 -0
- package/src/types.js +3 -0
- package/test-helpers/h.js +32 -0
- package/webpack.config.js +3 -0
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
var _react = _interopRequireDefault(require("react"));
|
|
8
|
+
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
9
|
+
var _decapCmsUiDefault = require("decap-cms-ui-default");
|
|
10
|
+
var _dompurify = _interopRequireDefault(require("dompurify"));
|
|
11
|
+
var _serializers = require("./serializers");
|
|
12
|
+
var _core = require("@emotion/core");
|
|
13
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
14
|
+
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
|
+
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
|
|
16
|
+
function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
|
|
17
|
+
class MarkdownPreview extends _react.default.Component {
|
|
18
|
+
render() {
|
|
19
|
+
const {
|
|
20
|
+
value,
|
|
21
|
+
getAsset,
|
|
22
|
+
resolveWidget,
|
|
23
|
+
field,
|
|
24
|
+
getRemarkPlugins
|
|
25
|
+
} = this.props;
|
|
26
|
+
if (value === null) {
|
|
27
|
+
return null;
|
|
28
|
+
}
|
|
29
|
+
const html = (0, _serializers.markdownToHtml)(value, {
|
|
30
|
+
getAsset,
|
|
31
|
+
resolveWidget
|
|
32
|
+
}, getRemarkPlugins === null || getRemarkPlugins === void 0 ? void 0 : getRemarkPlugins());
|
|
33
|
+
const toRender = field !== null && field !== void 0 && field.get('sanitize_preview', false) ? _dompurify.default.sanitize(html) : html;
|
|
34
|
+
return (0, _core.jsx)(_decapCmsUiDefault.WidgetPreviewContainer, {
|
|
35
|
+
dangerouslySetInnerHTML: {
|
|
36
|
+
__html: toRender
|
|
37
|
+
}
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
_defineProperty(MarkdownPreview, "propTypes", {
|
|
42
|
+
getAsset: _propTypes.default.func.isRequired,
|
|
43
|
+
resolveWidget: _propTypes.default.func.isRequired,
|
|
44
|
+
value: _propTypes.default.string
|
|
45
|
+
});
|
|
46
|
+
var _default = MarkdownPreview;
|
|
47
|
+
exports.default = _default;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = exports.DecapCmsWidgetMarkdown = void 0;
|
|
7
|
+
var _MarkdownControl = _interopRequireDefault(require("./MarkdownControl"));
|
|
8
|
+
var _MarkdownPreview = _interopRequireDefault(require("./MarkdownPreview"));
|
|
9
|
+
var _schema = _interopRequireDefault(require("./schema"));
|
|
10
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
11
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
12
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
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(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
|
|
15
|
+
function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
|
|
16
|
+
function Widget(opts = {}) {
|
|
17
|
+
return _objectSpread({
|
|
18
|
+
name: 'markdown',
|
|
19
|
+
controlComponent: _MarkdownControl.default,
|
|
20
|
+
previewComponent: _MarkdownPreview.default,
|
|
21
|
+
schema: _schema.default
|
|
22
|
+
}, opts);
|
|
23
|
+
}
|
|
24
|
+
const DecapCmsWidgetMarkdown = {
|
|
25
|
+
Widget,
|
|
26
|
+
controlComponent: _MarkdownControl.default,
|
|
27
|
+
previewComponent: _MarkdownPreview.default
|
|
28
|
+
};
|
|
29
|
+
exports.DecapCmsWidgetMarkdown = DecapCmsWidgetMarkdown;
|
|
30
|
+
var _default = DecapCmsWidgetMarkdown;
|
|
31
|
+
exports.default = _default;
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.combinePatterns = combinePatterns;
|
|
7
|
+
exports.joinPatternSegments = joinPatternSegments;
|
|
8
|
+
exports.replaceWhen = replaceWhen;
|
|
9
|
+
var _last2 = _interopRequireDefault(require("lodash/last"));
|
|
10
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
11
|
+
/**
|
|
12
|
+
* Joins an array of regular expressions into a single expression, without
|
|
13
|
+
* altering the received expressions.
|
|
14
|
+
*/
|
|
15
|
+
function joinPatternSegments(patterns) {
|
|
16
|
+
return patterns.map(p => p.source).join('');
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Combines an array of regular expressions into a single expression, wrapping
|
|
21
|
+
* each in a non-capturing group and interposing alternation characters (|) so
|
|
22
|
+
* that each expression is executed separately.
|
|
23
|
+
*/
|
|
24
|
+
function combinePatterns(patterns) {
|
|
25
|
+
return patterns.map(p => `(?:${p.source})`).join('|');
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Modify substrings within a string if they match a (global) pattern. Can be
|
|
30
|
+
* inverted to only modify non-matches.
|
|
31
|
+
*
|
|
32
|
+
* params:
|
|
33
|
+
* matchPattern - regexp - a regular expression to check for matches
|
|
34
|
+
* replaceFn - function - a replacement function that receives a matched
|
|
35
|
+
* substring and returns a replacement substring
|
|
36
|
+
* text - string - the string to process
|
|
37
|
+
* invertMatchPattern - boolean - if true, non-matching substrings are modified
|
|
38
|
+
* instead of matching substrings
|
|
39
|
+
*/
|
|
40
|
+
function replaceWhen(matchPattern, replaceFn, text, invertMatchPattern) {
|
|
41
|
+
/**
|
|
42
|
+
* Splits the string into an array of objects with the following shape:
|
|
43
|
+
*
|
|
44
|
+
* {
|
|
45
|
+
* index: number - the index of the substring within the string
|
|
46
|
+
* text: string - the substring
|
|
47
|
+
* match: boolean - true if the substring matched `matchPattern`
|
|
48
|
+
* }
|
|
49
|
+
*
|
|
50
|
+
* Loops through matches via recursion (`RegExp.exec` tracks the loop
|
|
51
|
+
* internally).
|
|
52
|
+
*/
|
|
53
|
+
function split(exp, text, acc) {
|
|
54
|
+
/**
|
|
55
|
+
* Get the next match starting from the end of the last match or start of
|
|
56
|
+
* string.
|
|
57
|
+
*/
|
|
58
|
+
const match = exp.exec(text);
|
|
59
|
+
const lastEntry = (0, _last2.default)(acc);
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* `match` will be null if there are no matches.
|
|
63
|
+
*/
|
|
64
|
+
if (!match) return acc;
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* If the match is at the beginning of the input string, normalize to a data
|
|
68
|
+
* object with the `match` flag set to `true`, and add to the accumulator.
|
|
69
|
+
*/
|
|
70
|
+
if (match.index === 0) {
|
|
71
|
+
addSubstring(acc, 0, match[0], true);
|
|
72
|
+
} else if (!lastEntry) {
|
|
73
|
+
/**
|
|
74
|
+
* If there are no entries in the accumulator, convert the substring before
|
|
75
|
+
* the match to a data object (without the `match` flag set to true) and
|
|
76
|
+
* push to the accumulator, followed by a data object for the matching
|
|
77
|
+
* substring.
|
|
78
|
+
*/
|
|
79
|
+
addSubstring(acc, 0, match.input.slice(0, match.index));
|
|
80
|
+
addSubstring(acc, match.index, match[0], true);
|
|
81
|
+
} else if (match.index === lastEntry.index + lastEntry.text.length) {
|
|
82
|
+
/**
|
|
83
|
+
* If the last entry in the accumulator immediately preceded the current
|
|
84
|
+
* matched substring in the original string, just add the data object for
|
|
85
|
+
* the matching substring to the accumulator.
|
|
86
|
+
*/
|
|
87
|
+
addSubstring(acc, match.index, match[0], true);
|
|
88
|
+
} else {
|
|
89
|
+
/**
|
|
90
|
+
* Convert the substring before the match to a data object (without the
|
|
91
|
+
* `match` flag set to true), followed by a data object for the matching
|
|
92
|
+
* substring.
|
|
93
|
+
*/
|
|
94
|
+
const nextIndex = lastEntry.index + lastEntry.text.length;
|
|
95
|
+
const nextText = match.input.slice(nextIndex, match.index);
|
|
96
|
+
addSubstring(acc, nextIndex, nextText);
|
|
97
|
+
addSubstring(acc, match.index, match[0], true);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* Continue executing the expression.
|
|
102
|
+
*/
|
|
103
|
+
return split(exp, text, acc);
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* Factory for converting substrings to data objects and adding to an output
|
|
108
|
+
* array.
|
|
109
|
+
*/
|
|
110
|
+
function addSubstring(arr, index, text, match = false) {
|
|
111
|
+
arr.push({
|
|
112
|
+
index,
|
|
113
|
+
text,
|
|
114
|
+
match
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* Split the input string to an array of data objects, each representing a
|
|
120
|
+
* matching or non-matching string.
|
|
121
|
+
*/
|
|
122
|
+
const acc = split(matchPattern, text, []);
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* Process the trailing substring after the final match, if one exists.
|
|
126
|
+
*/
|
|
127
|
+
const lastEntry = (0, _last2.default)(acc);
|
|
128
|
+
if (!lastEntry) return replaceFn(text);
|
|
129
|
+
const nextIndex = lastEntry.index + lastEntry.text.length;
|
|
130
|
+
if (text.length > nextIndex) {
|
|
131
|
+
acc.push({
|
|
132
|
+
index: nextIndex,
|
|
133
|
+
text: text.slice(nextIndex)
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
/**
|
|
138
|
+
* Map the data objects in the accumulator to their string values, modifying
|
|
139
|
+
* matched strings with the replacement function. Modifies non-matches if
|
|
140
|
+
* `invertMatchPattern` is truthy.
|
|
141
|
+
*/
|
|
142
|
+
const replacedText = acc.map(entry => {
|
|
143
|
+
const isMatch = invertMatchPattern ? !entry.match : entry.match;
|
|
144
|
+
return isMatch ? replaceFn(entry.text) : entry.text;
|
|
145
|
+
});
|
|
146
|
+
|
|
147
|
+
/**
|
|
148
|
+
* Return the joined string.
|
|
149
|
+
*/
|
|
150
|
+
return replacedText.join('');
|
|
151
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
var _default = {
|
|
8
|
+
properties: {
|
|
9
|
+
minimal: {
|
|
10
|
+
type: 'boolean'
|
|
11
|
+
},
|
|
12
|
+
buttons: {
|
|
13
|
+
type: 'array',
|
|
14
|
+
items: {
|
|
15
|
+
type: 'string',
|
|
16
|
+
enum: ['bold', 'italic', 'code', 'link', 'heading-one', 'heading-two', 'heading-three', 'heading-four', 'heading-five', 'heading-six', 'quote', 'bulleted-list', 'numbered-list']
|
|
17
|
+
}
|
|
18
|
+
},
|
|
19
|
+
editor_components: {
|
|
20
|
+
type: 'array',
|
|
21
|
+
items: {
|
|
22
|
+
type: 'string'
|
|
23
|
+
}
|
|
24
|
+
},
|
|
25
|
+
modes: {
|
|
26
|
+
type: 'array',
|
|
27
|
+
items: {
|
|
28
|
+
type: 'string',
|
|
29
|
+
enum: ['raw', 'rich_text']
|
|
30
|
+
},
|
|
31
|
+
minItems: 1
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
exports.default = _default;
|
|
@@ -0,0 +1,233 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.htmlToSlate = htmlToSlate;
|
|
7
|
+
exports.markdownToHtml = markdownToHtml;
|
|
8
|
+
exports.markdownToRemark = markdownToRemark;
|
|
9
|
+
exports.markdownToSlate = markdownToSlate;
|
|
10
|
+
exports.remarkToMarkdown = remarkToMarkdown;
|
|
11
|
+
exports.slateToMarkdown = slateToMarkdown;
|
|
12
|
+
var _trimEnd2 = _interopRequireDefault(require("lodash/trimEnd"));
|
|
13
|
+
var _unified = _interopRequireDefault(require("unified"));
|
|
14
|
+
var _unistBuilder = _interopRequireDefault(require("unist-builder"));
|
|
15
|
+
var _remarkParse = _interopRequireDefault(require("remark-parse"));
|
|
16
|
+
var _remarkStringify = _interopRequireDefault(require("remark-stringify"));
|
|
17
|
+
var _remarkRehype = _interopRequireDefault(require("remark-rehype"));
|
|
18
|
+
var _rehypeStringify = _interopRequireDefault(require("rehype-stringify"));
|
|
19
|
+
var _rehypeParse = _interopRequireDefault(require("rehype-parse"));
|
|
20
|
+
var _rehypeRemark = _interopRequireDefault(require("rehype-remark"));
|
|
21
|
+
var _remarkRehypeShortcodes = _interopRequireDefault(require("./remarkRehypeShortcodes"));
|
|
22
|
+
var _rehypePaperEmoji = _interopRequireDefault(require("./rehypePaperEmoji"));
|
|
23
|
+
var _remarkAssertParents = _interopRequireDefault(require("./remarkAssertParents"));
|
|
24
|
+
var _remarkPaddedLinks = _interopRequireDefault(require("./remarkPaddedLinks"));
|
|
25
|
+
var _remarkWrapHtml = _interopRequireDefault(require("./remarkWrapHtml"));
|
|
26
|
+
var _remarkSlate = _interopRequireDefault(require("./remarkSlate"));
|
|
27
|
+
var _remarkSquashReferences = _interopRequireDefault(require("./remarkSquashReferences"));
|
|
28
|
+
var _remarkShortcodes = require("./remarkShortcodes");
|
|
29
|
+
var _remarkEscapeMarkdownEntities = _interopRequireDefault(require("./remarkEscapeMarkdownEntities"));
|
|
30
|
+
var _remarkStripTrailingBreaks = _interopRequireDefault(require("./remarkStripTrailingBreaks"));
|
|
31
|
+
var _remarkAllowHtmlEntities = _interopRequireDefault(require("./remarkAllowHtmlEntities"));
|
|
32
|
+
var _slateRemark = _interopRequireDefault(require("./slateRemark"));
|
|
33
|
+
var _MarkdownControl = require("../MarkdownControl");
|
|
34
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
35
|
+
/**
|
|
36
|
+
* This module contains all serializers for the Markdown widget.
|
|
37
|
+
*
|
|
38
|
+
* The value of a Markdown widget is transformed to various formats during
|
|
39
|
+
* editing, and these formats are referenced throughout serializer source
|
|
40
|
+
* documentation. Below is brief glossary of the formats used.
|
|
41
|
+
*
|
|
42
|
+
* - Markdown {string}
|
|
43
|
+
* The stringified Markdown value. The value of the field is persisted
|
|
44
|
+
* (stored) in this format, and the stringified value is also used when the
|
|
45
|
+
* editor is in "raw" Markdown mode.
|
|
46
|
+
*
|
|
47
|
+
* - MDAST {object}
|
|
48
|
+
* Also loosely referred to as "Remark". MDAST stands for MarkDown AST
|
|
49
|
+
* (Abstract Syntax Tree), and is an object representation of a Markdown
|
|
50
|
+
* document. Underneath, it's a Unist tree with a Markdown-specific schema.
|
|
51
|
+
* MDAST syntax is a part of the Unified ecosystem, and powers the Remark
|
|
52
|
+
* processor, so Remark plugins may be used.
|
|
53
|
+
*
|
|
54
|
+
* - HAST {object}
|
|
55
|
+
* Also loosely referred to as "Rehype". HAST, similar to MDAST, is an object
|
|
56
|
+
* representation of an HTML document. The field value takes this format
|
|
57
|
+
* temporarily before the document is stringified to HTML.
|
|
58
|
+
*
|
|
59
|
+
* - HTML {string}
|
|
60
|
+
* The field value is stringifed to HTML for preview purposes - the HTML value
|
|
61
|
+
* is never parsed, it is output only.
|
|
62
|
+
*
|
|
63
|
+
* - Slate Raw AST {object}
|
|
64
|
+
* Slate's Raw AST is a very simple and unopinionated object representation of
|
|
65
|
+
* a document in a Slate editor. We define our own Markdown-specific schema
|
|
66
|
+
* for serialization to/from Slate's Raw AST and MDAST.
|
|
67
|
+
*/
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Deserialize a Markdown string to an MDAST.
|
|
71
|
+
*/
|
|
72
|
+
function markdownToRemark(markdown, remarkPlugins) {
|
|
73
|
+
const processor = (0, _unified.default)().use(_remarkParse.default, {
|
|
74
|
+
fences: true,
|
|
75
|
+
commonmark: true
|
|
76
|
+
}).use(markdownToRemarkRemoveTokenizers, {
|
|
77
|
+
inlineTokenizers: ['url']
|
|
78
|
+
}).use(_remarkShortcodes.remarkParseShortcodes, {
|
|
79
|
+
plugins: (0, _MarkdownControl.getEditorComponents)()
|
|
80
|
+
}).use(_remarkAllowHtmlEntities.default).use(_remarkSquashReferences.default).use(remarkPlugins);
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* Parse the Markdown string input to an MDAST.
|
|
84
|
+
*/
|
|
85
|
+
const parsed = processor.parse(markdown);
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* Further transform the MDAST with plugins.
|
|
89
|
+
*/
|
|
90
|
+
const result = processor.runSync(parsed);
|
|
91
|
+
return result;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* Remove named tokenizers from the parser, effectively deactivating them.
|
|
96
|
+
*/
|
|
97
|
+
function markdownToRemarkRemoveTokenizers({
|
|
98
|
+
inlineTokenizers
|
|
99
|
+
}) {
|
|
100
|
+
inlineTokenizers && inlineTokenizers.forEach(tokenizer => {
|
|
101
|
+
delete this.Parser.prototype.inlineTokenizers[tokenizer];
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* Serialize an MDAST to a Markdown string.
|
|
107
|
+
*/
|
|
108
|
+
function remarkToMarkdown(obj, remarkPlugins) {
|
|
109
|
+
/**
|
|
110
|
+
* Rewrite the remark-stringify text visitor to simply return the text value,
|
|
111
|
+
* without encoding or escaping any characters. This means we're completely
|
|
112
|
+
* trusting the markdown that we receive.
|
|
113
|
+
*/
|
|
114
|
+
function remarkAllowAllText() {
|
|
115
|
+
const Compiler = this.Compiler;
|
|
116
|
+
const visitors = Compiler.prototype.visitors;
|
|
117
|
+
visitors.text = node => node.value;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* Provide an empty MDAST if no value is provided.
|
|
122
|
+
*/
|
|
123
|
+
const mdast = obj || (0, _unistBuilder.default)('root', [(0, _unistBuilder.default)('paragraph', [(0, _unistBuilder.default)('text', '')])]);
|
|
124
|
+
const remarkToMarkdownPluginOpts = {
|
|
125
|
+
commonmark: true,
|
|
126
|
+
fences: true,
|
|
127
|
+
listItemIndent: '1',
|
|
128
|
+
/**
|
|
129
|
+
* Use asterisk for everything, it's the most versatile. Eventually using
|
|
130
|
+
* other characters should be an option.
|
|
131
|
+
*/
|
|
132
|
+
bullet: '*',
|
|
133
|
+
emphasis: '*',
|
|
134
|
+
strong: '*',
|
|
135
|
+
rule: '-'
|
|
136
|
+
};
|
|
137
|
+
const processor = (0, _unified.default)().use({
|
|
138
|
+
settings: remarkToMarkdownPluginOpts
|
|
139
|
+
}).use(_remarkEscapeMarkdownEntities.default).use(_remarkStripTrailingBreaks.default).use(_remarkStringify.default).use(remarkAllowAllText).use((0, _remarkShortcodes.createRemarkShortcodeStringifier)({
|
|
140
|
+
plugins: (0, _MarkdownControl.getEditorComponents)()
|
|
141
|
+
})).use(remarkPlugins);
|
|
142
|
+
|
|
143
|
+
/**
|
|
144
|
+
* Transform the MDAST with plugins.
|
|
145
|
+
*/
|
|
146
|
+
const processedMdast = processor.runSync(mdast);
|
|
147
|
+
|
|
148
|
+
/**
|
|
149
|
+
* Serialize the MDAST to markdown.
|
|
150
|
+
*/
|
|
151
|
+
const markdown = processor.stringify(processedMdast).replace(/\r?/g, '');
|
|
152
|
+
|
|
153
|
+
/**
|
|
154
|
+
* Return markdown with trailing whitespace removed.
|
|
155
|
+
*/
|
|
156
|
+
return (0, _trimEnd2.default)(markdown);
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
/**
|
|
160
|
+
* Convert Markdown to HTML.
|
|
161
|
+
*/
|
|
162
|
+
function markdownToHtml(markdown, {
|
|
163
|
+
getAsset,
|
|
164
|
+
resolveWidget,
|
|
165
|
+
remarkPlugins = []
|
|
166
|
+
} = {}) {
|
|
167
|
+
const mdast = markdownToRemark(markdown, remarkPlugins);
|
|
168
|
+
const hast = (0, _unified.default)().use(_remarkRehypeShortcodes.default, {
|
|
169
|
+
plugins: (0, _MarkdownControl.getEditorComponents)(),
|
|
170
|
+
getAsset,
|
|
171
|
+
resolveWidget
|
|
172
|
+
}).use(_remarkRehype.default, {
|
|
173
|
+
allowDangerousHTML: true
|
|
174
|
+
}).runSync(mdast);
|
|
175
|
+
const html = (0, _unified.default)().use(_rehypeStringify.default, {
|
|
176
|
+
allowDangerousHtml: true,
|
|
177
|
+
allowDangerousCharacters: true,
|
|
178
|
+
closeSelfClosing: true,
|
|
179
|
+
entities: {
|
|
180
|
+
useNamedReferences: true
|
|
181
|
+
}
|
|
182
|
+
}).stringify(hast);
|
|
183
|
+
return html;
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
/**
|
|
187
|
+
* Deserialize an HTML string to Slate's Raw AST. Currently used for HTML
|
|
188
|
+
* pastes.
|
|
189
|
+
*/
|
|
190
|
+
function htmlToSlate(html) {
|
|
191
|
+
const hast = (0, _unified.default)().use(_rehypeParse.default, {
|
|
192
|
+
fragment: true
|
|
193
|
+
}).parse(html);
|
|
194
|
+
const mdast = (0, _unified.default)().use(_rehypePaperEmoji.default).use(_rehypeRemark.default, {
|
|
195
|
+
minify: false
|
|
196
|
+
}).runSync(hast);
|
|
197
|
+
const slateRaw = (0, _unified.default)().use(_remarkAssertParents.default).use(_remarkPaddedLinks.default).use(_remarkWrapHtml.default).use(_remarkSlate.default).runSync(mdast);
|
|
198
|
+
return slateRaw;
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
/**
|
|
202
|
+
* Convert Markdown to Slate's Raw AST.
|
|
203
|
+
*/
|
|
204
|
+
function markdownToSlate(markdown, {
|
|
205
|
+
voidCodeBlock,
|
|
206
|
+
remarkPlugins = []
|
|
207
|
+
} = {}) {
|
|
208
|
+
const mdast = markdownToRemark(markdown, remarkPlugins);
|
|
209
|
+
const slateRaw = (0, _unified.default)().use(_remarkWrapHtml.default).use(_remarkSlate.default, {
|
|
210
|
+
voidCodeBlock
|
|
211
|
+
}).runSync(mdast);
|
|
212
|
+
return slateRaw.children;
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
/**
|
|
216
|
+
* Convert a Slate Raw AST to Markdown.
|
|
217
|
+
*
|
|
218
|
+
* Requires shortcode plugins to parse shortcode nodes back to text.
|
|
219
|
+
*
|
|
220
|
+
* Note that Unified is not utilized for the conversion from Slate's Raw AST to
|
|
221
|
+
* MDAST. The conversion is manual because Unified can only operate on Unist
|
|
222
|
+
* trees.
|
|
223
|
+
*/
|
|
224
|
+
function slateToMarkdown(raw, {
|
|
225
|
+
voidCodeBlock,
|
|
226
|
+
remarkPlugins = []
|
|
227
|
+
} = {}) {
|
|
228
|
+
const mdast = (0, _slateRemark.default)(raw, {
|
|
229
|
+
voidCodeBlock
|
|
230
|
+
});
|
|
231
|
+
const markdown = remarkToMarkdown(mdast, remarkPlugins);
|
|
232
|
+
return markdown;
|
|
233
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = rehypePaperEmoji;
|
|
7
|
+
/**
|
|
8
|
+
* Dropbox Paper outputs emoji characters as images, and stores the actual
|
|
9
|
+
* emoji character in a `data-emoji-ch` attribute on the image. This plugin
|
|
10
|
+
* replaces the images with the emoji characters.
|
|
11
|
+
*/
|
|
12
|
+
function rehypePaperEmoji() {
|
|
13
|
+
function transform(node) {
|
|
14
|
+
if (node.tagName === 'img' && node.properties.dataEmojiCh) {
|
|
15
|
+
return {
|
|
16
|
+
type: 'text',
|
|
17
|
+
value: node.properties.dataEmojiCh
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
node.children = node.children ? node.children.map(transform) : node.children;
|
|
21
|
+
return node;
|
|
22
|
+
}
|
|
23
|
+
return transform;
|
|
24
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = remarkAllowHtmlEntities;
|
|
7
|
+
function remarkAllowHtmlEntities() {
|
|
8
|
+
this.Parser.prototype.inlineTokenizers.text = text;
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* This is a port of the `remark-parse` text tokenizer, adapted to exclude
|
|
12
|
+
* HTML entity decoding.
|
|
13
|
+
*/
|
|
14
|
+
function text(eat, value, silent) {
|
|
15
|
+
var self = this;
|
|
16
|
+
var methods;
|
|
17
|
+
var tokenizers;
|
|
18
|
+
var index;
|
|
19
|
+
var length;
|
|
20
|
+
var subvalue;
|
|
21
|
+
var position;
|
|
22
|
+
var tokenizer;
|
|
23
|
+
var name;
|
|
24
|
+
var min;
|
|
25
|
+
|
|
26
|
+
/* istanbul ignore if - never used (yet) */
|
|
27
|
+
if (silent) {
|
|
28
|
+
return true;
|
|
29
|
+
}
|
|
30
|
+
methods = self.inlineMethods;
|
|
31
|
+
length = methods.length;
|
|
32
|
+
tokenizers = self.inlineTokenizers;
|
|
33
|
+
index = -1;
|
|
34
|
+
min = value.length;
|
|
35
|
+
while (++index < length) {
|
|
36
|
+
name = methods[index];
|
|
37
|
+
if (name === 'text' || !tokenizers[name]) {
|
|
38
|
+
continue;
|
|
39
|
+
}
|
|
40
|
+
tokenizer = tokenizers[name].locator;
|
|
41
|
+
if (!tokenizer) {
|
|
42
|
+
eat.file.fail('Missing locator: `' + name + '`');
|
|
43
|
+
}
|
|
44
|
+
position = tokenizer.call(self, value, 1);
|
|
45
|
+
if (position !== -1 && position < min) {
|
|
46
|
+
min = position;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
subvalue = value.slice(0, min);
|
|
50
|
+
eat(subvalue)({
|
|
51
|
+
type: 'text',
|
|
52
|
+
value: subvalue
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = remarkUnwrapInvalidNest;
|
|
7
|
+
var _isEmpty2 = _interopRequireDefault(require("lodash/isEmpty"));
|
|
8
|
+
var _nth2 = _interopRequireDefault(require("lodash/nth"));
|
|
9
|
+
var _last2 = _interopRequireDefault(require("lodash/last"));
|
|
10
|
+
var _concat2 = _interopRequireDefault(require("lodash/concat"));
|
|
11
|
+
var _unistUtilVisitParents = _interopRequireDefault(require("unist-util-visit-parents"));
|
|
12
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
13
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
14
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
15
|
+
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
|
+
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
|
|
17
|
+
function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
|
|
18
|
+
/**
|
|
19
|
+
* remarkUnwrapInvalidNest
|
|
20
|
+
*
|
|
21
|
+
* Some MDAST node types can only be nested within specific node types - for
|
|
22
|
+
* example, a paragraph can't be nested within another paragraph, and a heading
|
|
23
|
+
* can't be nested in a "strong" type node. This kind of invalid MDAST can be
|
|
24
|
+
* generated by rehype-remark from invalid HTML.
|
|
25
|
+
*
|
|
26
|
+
* This plugin finds instances of invalid nesting, and unwraps the invalidly
|
|
27
|
+
* nested nodes as far up the parental line as necessary, splitting parent nodes
|
|
28
|
+
* along the way. The resulting node has no invalidly nested nodes, and all
|
|
29
|
+
* validly nested nodes retain their ancestry. Nodes that are emptied as a
|
|
30
|
+
* result of unnesting nodes are removed from the tree.
|
|
31
|
+
*/
|
|
32
|
+
function remarkUnwrapInvalidNest() {
|
|
33
|
+
return transform;
|
|
34
|
+
function transform(tree) {
|
|
35
|
+
const invalidNest = findInvalidNest(tree);
|
|
36
|
+
if (!invalidNest) return tree;
|
|
37
|
+
splitTreeAtNest(tree, invalidNest);
|
|
38
|
+
return transform(tree);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* visitParents uses unist-util-visit-parent to check every node in the
|
|
43
|
+
* tree while having access to every ancestor of the node. This is ideal
|
|
44
|
+
* for determining whether a block node has an ancestor that should not
|
|
45
|
+
* contain a block node. Note that it operates in a mutable fashion.
|
|
46
|
+
*/
|
|
47
|
+
function findInvalidNest(tree) {
|
|
48
|
+
/**
|
|
49
|
+
* Node types that are considered "blocks".
|
|
50
|
+
*/
|
|
51
|
+
const blocks = ['paragraph', 'heading', 'code', 'blockquote', 'list', 'table', 'thematicBreak'];
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Node types that can contain "block" nodes as direct children. We check
|
|
55
|
+
*/
|
|
56
|
+
const canContainBlocks = ['root', 'blockquote', 'listItem', 'tableCell'];
|
|
57
|
+
let invalidNest;
|
|
58
|
+
(0, _unistUtilVisitParents.default)(tree, (node, parents) => {
|
|
59
|
+
const parentType = !(0, _isEmpty2.default)(parents) && (0, _last2.default)(parents).type;
|
|
60
|
+
const isInvalidNest = blocks.includes(node.type) && !canContainBlocks.includes(parentType);
|
|
61
|
+
if (isInvalidNest) {
|
|
62
|
+
invalidNest = (0, _concat2.default)(parents, node);
|
|
63
|
+
return false;
|
|
64
|
+
}
|
|
65
|
+
});
|
|
66
|
+
return invalidNest;
|
|
67
|
+
}
|
|
68
|
+
function splitTreeAtNest(tree, nest) {
|
|
69
|
+
const grandparent = (0, _nth2.default)(nest, -3) || tree;
|
|
70
|
+
const parent = (0, _nth2.default)(nest, -2);
|
|
71
|
+
const node = (0, _last2.default)(nest);
|
|
72
|
+
const splitIndex = grandparent.children.indexOf(parent);
|
|
73
|
+
const splitChildren = grandparent.children;
|
|
74
|
+
const splitChildIndex = parent.children.indexOf(node);
|
|
75
|
+
const childrenBefore = parent.children.slice(0, splitChildIndex);
|
|
76
|
+
const childrenAfter = parent.children.slice(splitChildIndex + 1);
|
|
77
|
+
const nodeBefore = !(0, _isEmpty2.default)(childrenBefore) && _objectSpread(_objectSpread({}, parent), {}, {
|
|
78
|
+
children: childrenBefore
|
|
79
|
+
});
|
|
80
|
+
const nodeAfter = !(0, _isEmpty2.default)(childrenAfter) && _objectSpread(_objectSpread({}, parent), {}, {
|
|
81
|
+
children: childrenAfter
|
|
82
|
+
});
|
|
83
|
+
const childrenToInsert = [nodeBefore, node, nodeAfter].filter(val => !(0, _isEmpty2.default)(val));
|
|
84
|
+
const beforeChildren = splitChildren.slice(0, splitIndex);
|
|
85
|
+
const afterChildren = splitChildren.slice(splitIndex + 1);
|
|
86
|
+
const newChildren = (0, _concat2.default)(beforeChildren, childrenToInsert, afterChildren);
|
|
87
|
+
grandparent.children = newChildren;
|
|
88
|
+
}
|
|
89
|
+
}
|