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,299 @@
|
|
|
1
|
+
import visit from 'unist-util-visit';
|
|
2
|
+
|
|
3
|
+
import { markdownToRemark, remarkToMarkdown } from '..';
|
|
4
|
+
|
|
5
|
+
describe('registered remark plugins', () => {
|
|
6
|
+
function withNetlifyLinks() {
|
|
7
|
+
return function transformer(tree) {
|
|
8
|
+
visit(tree, 'link', function onLink(node) {
|
|
9
|
+
node.url = 'https://netlify.com';
|
|
10
|
+
});
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
it('should use remark transformer plugins when converting mdast to markdown', () => {
|
|
15
|
+
const plugins = [withNetlifyLinks];
|
|
16
|
+
const result = remarkToMarkdown(
|
|
17
|
+
{
|
|
18
|
+
type: 'root',
|
|
19
|
+
children: [
|
|
20
|
+
{
|
|
21
|
+
type: 'paragraph',
|
|
22
|
+
children: [
|
|
23
|
+
{
|
|
24
|
+
type: 'text',
|
|
25
|
+
value: 'Some ',
|
|
26
|
+
},
|
|
27
|
+
{
|
|
28
|
+
type: 'emphasis',
|
|
29
|
+
children: [
|
|
30
|
+
{
|
|
31
|
+
type: 'text',
|
|
32
|
+
value: 'important',
|
|
33
|
+
},
|
|
34
|
+
],
|
|
35
|
+
},
|
|
36
|
+
{
|
|
37
|
+
type: 'text',
|
|
38
|
+
value: ' text with ',
|
|
39
|
+
},
|
|
40
|
+
{
|
|
41
|
+
type: 'link',
|
|
42
|
+
title: null,
|
|
43
|
+
url: 'https://this-value-should-be-replaced.com',
|
|
44
|
+
children: [
|
|
45
|
+
{
|
|
46
|
+
type: 'text',
|
|
47
|
+
value: 'a link',
|
|
48
|
+
},
|
|
49
|
+
],
|
|
50
|
+
},
|
|
51
|
+
{
|
|
52
|
+
type: 'text',
|
|
53
|
+
value: ' in it.',
|
|
54
|
+
},
|
|
55
|
+
],
|
|
56
|
+
},
|
|
57
|
+
],
|
|
58
|
+
},
|
|
59
|
+
plugins,
|
|
60
|
+
);
|
|
61
|
+
expect(result).toMatchInlineSnapshot(
|
|
62
|
+
`"Some *important* text with [a link](https://netlify.com) in it."`,
|
|
63
|
+
);
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
it('should use remark transformer plugins when converting markdown to mdast', () => {
|
|
67
|
+
const plugins = [withNetlifyLinks];
|
|
68
|
+
const result = markdownToRemark(
|
|
69
|
+
'Some text with [a link](https://this-value-should-be-replaced.com) in it.',
|
|
70
|
+
plugins,
|
|
71
|
+
);
|
|
72
|
+
expect(result).toMatchInlineSnapshot(`
|
|
73
|
+
Object {
|
|
74
|
+
"children": Array [
|
|
75
|
+
Object {
|
|
76
|
+
"children": Array [
|
|
77
|
+
Object {
|
|
78
|
+
"children": Array [],
|
|
79
|
+
"position": Position {
|
|
80
|
+
"end": Object {
|
|
81
|
+
"column": 16,
|
|
82
|
+
"line": 1,
|
|
83
|
+
"offset": 15,
|
|
84
|
+
},
|
|
85
|
+
"indent": Array [],
|
|
86
|
+
"start": Object {
|
|
87
|
+
"column": 1,
|
|
88
|
+
"line": 1,
|
|
89
|
+
"offset": 0,
|
|
90
|
+
},
|
|
91
|
+
},
|
|
92
|
+
"type": "text",
|
|
93
|
+
"value": "Some text with ",
|
|
94
|
+
},
|
|
95
|
+
Object {
|
|
96
|
+
"children": Array [
|
|
97
|
+
Object {
|
|
98
|
+
"children": Array [],
|
|
99
|
+
"position": Position {
|
|
100
|
+
"end": Object {
|
|
101
|
+
"column": 23,
|
|
102
|
+
"line": 1,
|
|
103
|
+
"offset": 22,
|
|
104
|
+
},
|
|
105
|
+
"indent": Array [],
|
|
106
|
+
"start": Object {
|
|
107
|
+
"column": 17,
|
|
108
|
+
"line": 1,
|
|
109
|
+
"offset": 16,
|
|
110
|
+
},
|
|
111
|
+
},
|
|
112
|
+
"type": "text",
|
|
113
|
+
"value": "a link",
|
|
114
|
+
},
|
|
115
|
+
],
|
|
116
|
+
"position": Position {
|
|
117
|
+
"end": Object {
|
|
118
|
+
"column": 67,
|
|
119
|
+
"line": 1,
|
|
120
|
+
"offset": 66,
|
|
121
|
+
},
|
|
122
|
+
"indent": Array [],
|
|
123
|
+
"start": Object {
|
|
124
|
+
"column": 16,
|
|
125
|
+
"line": 1,
|
|
126
|
+
"offset": 15,
|
|
127
|
+
},
|
|
128
|
+
},
|
|
129
|
+
"title": null,
|
|
130
|
+
"type": "link",
|
|
131
|
+
"url": "https://netlify.com",
|
|
132
|
+
},
|
|
133
|
+
Object {
|
|
134
|
+
"children": Array [],
|
|
135
|
+
"position": Position {
|
|
136
|
+
"end": Object {
|
|
137
|
+
"column": 74,
|
|
138
|
+
"line": 1,
|
|
139
|
+
"offset": 73,
|
|
140
|
+
},
|
|
141
|
+
"indent": Array [],
|
|
142
|
+
"start": Object {
|
|
143
|
+
"column": 67,
|
|
144
|
+
"line": 1,
|
|
145
|
+
"offset": 66,
|
|
146
|
+
},
|
|
147
|
+
},
|
|
148
|
+
"type": "text",
|
|
149
|
+
"value": " in it.",
|
|
150
|
+
},
|
|
151
|
+
],
|
|
152
|
+
"position": Position {
|
|
153
|
+
"end": Object {
|
|
154
|
+
"column": 74,
|
|
155
|
+
"line": 1,
|
|
156
|
+
"offset": 73,
|
|
157
|
+
},
|
|
158
|
+
"indent": Array [],
|
|
159
|
+
"start": Object {
|
|
160
|
+
"column": 1,
|
|
161
|
+
"line": 1,
|
|
162
|
+
"offset": 0,
|
|
163
|
+
},
|
|
164
|
+
},
|
|
165
|
+
"type": "paragraph",
|
|
166
|
+
},
|
|
167
|
+
],
|
|
168
|
+
"position": Object {
|
|
169
|
+
"end": Object {
|
|
170
|
+
"column": 74,
|
|
171
|
+
"line": 1,
|
|
172
|
+
"offset": 73,
|
|
173
|
+
},
|
|
174
|
+
"start": Object {
|
|
175
|
+
"column": 1,
|
|
176
|
+
"line": 1,
|
|
177
|
+
"offset": 0,
|
|
178
|
+
},
|
|
179
|
+
},
|
|
180
|
+
"type": "root",
|
|
181
|
+
}
|
|
182
|
+
`);
|
|
183
|
+
});
|
|
184
|
+
|
|
185
|
+
it('should use remark serializer plugins when converting mdast to markdown', () => {
|
|
186
|
+
function withEscapedLessThanChar() {
|
|
187
|
+
if (this.Compiler) {
|
|
188
|
+
this.Compiler.prototype.visitors.text = node => {
|
|
189
|
+
return node.value.replace(/</g, '<');
|
|
190
|
+
};
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
const plugins = [withEscapedLessThanChar];
|
|
195
|
+
const result = remarkToMarkdown(
|
|
196
|
+
{
|
|
197
|
+
type: 'root',
|
|
198
|
+
children: [
|
|
199
|
+
{
|
|
200
|
+
type: 'paragraph',
|
|
201
|
+
children: [
|
|
202
|
+
{
|
|
203
|
+
type: 'text',
|
|
204
|
+
value: '<3 Netlify',
|
|
205
|
+
},
|
|
206
|
+
],
|
|
207
|
+
},
|
|
208
|
+
],
|
|
209
|
+
},
|
|
210
|
+
plugins,
|
|
211
|
+
);
|
|
212
|
+
expect(result).toMatchInlineSnapshot(`"<3 Netlify"`);
|
|
213
|
+
});
|
|
214
|
+
|
|
215
|
+
it('should use remark preset with settings when converting mdast to markdown', () => {
|
|
216
|
+
const settings = {
|
|
217
|
+
emphasis: '_',
|
|
218
|
+
bullet: '-',
|
|
219
|
+
};
|
|
220
|
+
|
|
221
|
+
const plugins = [{ settings }];
|
|
222
|
+
const result = remarkToMarkdown(
|
|
223
|
+
{
|
|
224
|
+
type: 'root',
|
|
225
|
+
children: [
|
|
226
|
+
{
|
|
227
|
+
type: 'paragraph',
|
|
228
|
+
children: [
|
|
229
|
+
{
|
|
230
|
+
type: 'text',
|
|
231
|
+
value: 'Some ',
|
|
232
|
+
},
|
|
233
|
+
{
|
|
234
|
+
type: 'emphasis',
|
|
235
|
+
children: [
|
|
236
|
+
{
|
|
237
|
+
type: 'text',
|
|
238
|
+
value: 'important',
|
|
239
|
+
},
|
|
240
|
+
],
|
|
241
|
+
},
|
|
242
|
+
{
|
|
243
|
+
type: 'text',
|
|
244
|
+
value: ' points:',
|
|
245
|
+
},
|
|
246
|
+
],
|
|
247
|
+
},
|
|
248
|
+
{
|
|
249
|
+
type: 'list',
|
|
250
|
+
ordered: false,
|
|
251
|
+
start: null,
|
|
252
|
+
spread: false,
|
|
253
|
+
children: [
|
|
254
|
+
{
|
|
255
|
+
type: 'listItem',
|
|
256
|
+
spread: false,
|
|
257
|
+
checked: null,
|
|
258
|
+
children: [
|
|
259
|
+
{
|
|
260
|
+
type: 'paragraph',
|
|
261
|
+
children: [
|
|
262
|
+
{
|
|
263
|
+
type: 'text',
|
|
264
|
+
value: 'One',
|
|
265
|
+
},
|
|
266
|
+
],
|
|
267
|
+
},
|
|
268
|
+
],
|
|
269
|
+
},
|
|
270
|
+
{
|
|
271
|
+
type: 'listItem',
|
|
272
|
+
spread: false,
|
|
273
|
+
checked: null,
|
|
274
|
+
children: [
|
|
275
|
+
{
|
|
276
|
+
type: 'paragraph',
|
|
277
|
+
children: [
|
|
278
|
+
{
|
|
279
|
+
type: 'text',
|
|
280
|
+
value: 'Two',
|
|
281
|
+
},
|
|
282
|
+
],
|
|
283
|
+
},
|
|
284
|
+
],
|
|
285
|
+
},
|
|
286
|
+
],
|
|
287
|
+
},
|
|
288
|
+
],
|
|
289
|
+
},
|
|
290
|
+
plugins,
|
|
291
|
+
);
|
|
292
|
+
expect(result).toMatchInlineSnapshot(`
|
|
293
|
+
"Some _important_ points:
|
|
294
|
+
|
|
295
|
+
- One
|
|
296
|
+
- Two"
|
|
297
|
+
`);
|
|
298
|
+
});
|
|
299
|
+
});
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import { Map, OrderedMap } from 'immutable';
|
|
2
|
+
|
|
3
|
+
import { remarkParseShortcodes, getLinesWithOffsets } from '../remarkShortcodes';
|
|
4
|
+
|
|
5
|
+
// Stub of Remark Parser
|
|
6
|
+
function process(value, plugins, processEat = () => {}) {
|
|
7
|
+
function eat() {
|
|
8
|
+
return processEat;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
function Parser() {}
|
|
12
|
+
Parser.prototype.blockTokenizers = {};
|
|
13
|
+
Parser.prototype.blockMethods = [];
|
|
14
|
+
remarkParseShortcodes.call({ Parser }, { plugins });
|
|
15
|
+
Parser.prototype.blockTokenizers.shortcode(eat, value);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
function EditorComponent({ id = 'foo', fromBlock = jest.fn(), pattern }) {
|
|
19
|
+
return {
|
|
20
|
+
id,
|
|
21
|
+
fromBlock,
|
|
22
|
+
pattern,
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
describe('remarkParseShortcodes', () => {
|
|
27
|
+
describe('pattern matching', () => {
|
|
28
|
+
it('should work', () => {
|
|
29
|
+
const editorComponent = EditorComponent({ pattern: /bar/ });
|
|
30
|
+
process('foo bar', Map({ [editorComponent.id]: editorComponent }));
|
|
31
|
+
expect(editorComponent.fromBlock).toHaveBeenCalledWith(expect.arrayContaining(['bar']));
|
|
32
|
+
});
|
|
33
|
+
it('should match value surrounded in newlines', () => {
|
|
34
|
+
const editorComponent = EditorComponent({ pattern: /^bar$/ });
|
|
35
|
+
process('foo\n\nbar\n', Map({ [editorComponent.id]: editorComponent }));
|
|
36
|
+
expect(editorComponent.fromBlock).toHaveBeenCalledWith(expect.arrayContaining(['bar']));
|
|
37
|
+
});
|
|
38
|
+
it('should match multiline shortcodes', () => {
|
|
39
|
+
const editorComponent = EditorComponent({ pattern: /^foo\nbar$/ });
|
|
40
|
+
process('foo\nbar', Map({ [editorComponent.id]: editorComponent }));
|
|
41
|
+
expect(editorComponent.fromBlock).toHaveBeenCalledWith(expect.arrayContaining(['foo\nbar']));
|
|
42
|
+
});
|
|
43
|
+
it('should match multiline shortcodes with empty lines', () => {
|
|
44
|
+
const editorComponent = EditorComponent({ pattern: /^foo\n\nbar$/ });
|
|
45
|
+
process('foo\n\nbar', Map({ [editorComponent.id]: editorComponent }));
|
|
46
|
+
expect(editorComponent.fromBlock).toHaveBeenCalledWith(
|
|
47
|
+
expect.arrayContaining(['foo\n\nbar']),
|
|
48
|
+
);
|
|
49
|
+
});
|
|
50
|
+
it('should match shortcodes based on order of occurrence in value', () => {
|
|
51
|
+
const fooEditorComponent = EditorComponent({ id: 'foo', pattern: /foo/ });
|
|
52
|
+
const barEditorComponent = EditorComponent({ id: 'bar', pattern: /bar/ });
|
|
53
|
+
process(
|
|
54
|
+
'foo\n\nbar',
|
|
55
|
+
OrderedMap([
|
|
56
|
+
[barEditorComponent.id, barEditorComponent],
|
|
57
|
+
[fooEditorComponent.id, fooEditorComponent],
|
|
58
|
+
]),
|
|
59
|
+
);
|
|
60
|
+
expect(fooEditorComponent.fromBlock).toHaveBeenCalledWith(expect.arrayContaining(['foo']));
|
|
61
|
+
});
|
|
62
|
+
it('should match shortcodes based on order of occurrence in value even when some use line anchors', () => {
|
|
63
|
+
const barEditorComponent = EditorComponent({ id: 'bar', pattern: /bar/ });
|
|
64
|
+
const bazEditorComponent = EditorComponent({ id: 'baz', pattern: /^baz$/ });
|
|
65
|
+
process(
|
|
66
|
+
'foo\n\nbar\n\nbaz',
|
|
67
|
+
OrderedMap([
|
|
68
|
+
[bazEditorComponent.id, bazEditorComponent],
|
|
69
|
+
[barEditorComponent.id, barEditorComponent],
|
|
70
|
+
]),
|
|
71
|
+
);
|
|
72
|
+
expect(barEditorComponent.fromBlock).toHaveBeenCalledWith(expect.arrayContaining(['bar']));
|
|
73
|
+
});
|
|
74
|
+
});
|
|
75
|
+
describe('output', () => {
|
|
76
|
+
it('should be a remark shortcode node', () => {
|
|
77
|
+
const processEat = jest.fn();
|
|
78
|
+
const shortcodeData = { bar: 'baz' };
|
|
79
|
+
const expectedNode = { type: 'shortcode', data: { shortcode: 'foo', shortcodeData } };
|
|
80
|
+
const editorComponent = EditorComponent({ pattern: /bar/, fromBlock: () => shortcodeData });
|
|
81
|
+
process('foo bar', Map({ [editorComponent.id]: editorComponent }), processEat);
|
|
82
|
+
expect(processEat).toHaveBeenCalledWith(expectedNode);
|
|
83
|
+
});
|
|
84
|
+
});
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
describe('getLinesWithOffsets', () => {
|
|
88
|
+
test('should split into lines', () => {
|
|
89
|
+
const value = ' line1\n\nline2 \n\n line3 \n\n';
|
|
90
|
+
|
|
91
|
+
const lines = getLinesWithOffsets(value);
|
|
92
|
+
expect(lines).toEqual([
|
|
93
|
+
{ line: ' line1', start: 0 },
|
|
94
|
+
{ line: 'line2', start: 8 },
|
|
95
|
+
{ line: ' line3', start: 16 },
|
|
96
|
+
{ line: '', start: 30 },
|
|
97
|
+
]);
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
test('should return single item on no match', () => {
|
|
101
|
+
const value = ' line1 ';
|
|
102
|
+
|
|
103
|
+
const lines = getLinesWithOffsets(value);
|
|
104
|
+
expect(lines).toEqual([{ line: ' line1', start: 0 }]);
|
|
105
|
+
});
|
|
106
|
+
});
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { mergeAdjacentTexts } from '../remarkSlate';
|
|
2
|
+
describe('remarkSlate', () => {
|
|
3
|
+
describe('mergeAdjacentTexts', () => {
|
|
4
|
+
it('should handle empty array', () => {
|
|
5
|
+
const children = [];
|
|
6
|
+
expect(mergeAdjacentTexts(children)).toBe(children);
|
|
7
|
+
});
|
|
8
|
+
|
|
9
|
+
it('should merge adjacent texts with same marks', () => {
|
|
10
|
+
const children = [
|
|
11
|
+
{ text: '<a href="https://www.netlify.com" target="_blank">', marks: [] },
|
|
12
|
+
{ text: 'Netlify', marks: [] },
|
|
13
|
+
{ text: '</a>', marks: [] },
|
|
14
|
+
];
|
|
15
|
+
|
|
16
|
+
expect(mergeAdjacentTexts(children)).toEqual([
|
|
17
|
+
{
|
|
18
|
+
text: '<a href="https://www.netlify.com" target="_blank">Netlify</a>',
|
|
19
|
+
marks: [],
|
|
20
|
+
},
|
|
21
|
+
]);
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
it('should not merge adjacent texts with different marks', () => {
|
|
25
|
+
const children = [
|
|
26
|
+
{ text: '<a href="https://www.netlify.com" target="_blank">', marks: [] },
|
|
27
|
+
{ text: 'Netlify', marks: ['b'] },
|
|
28
|
+
{ text: '</a>', marks: [] },
|
|
29
|
+
];
|
|
30
|
+
|
|
31
|
+
expect(mergeAdjacentTexts(children)).toEqual(children);
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
it('should handle mixed children array', () => {
|
|
35
|
+
const children = [
|
|
36
|
+
{ object: 'inline' },
|
|
37
|
+
{ text: '<a href="https://www.netlify.com" target="_blank">', marks: [] },
|
|
38
|
+
{ text: 'Netlify', marks: [] },
|
|
39
|
+
{ text: '</a>', marks: [] },
|
|
40
|
+
{ object: 'inline' },
|
|
41
|
+
{ text: '<a href="https://www.netlify.com" target="_blank">', marks: [] },
|
|
42
|
+
{ text: 'Netlify', marks: ['b'] },
|
|
43
|
+
{ text: '</a>', marks: [] },
|
|
44
|
+
{ text: '<a href="https://www.netlify.com" target="_blank">', marks: [] },
|
|
45
|
+
{ object: 'inline' },
|
|
46
|
+
{ text: '</a>', marks: [] },
|
|
47
|
+
];
|
|
48
|
+
|
|
49
|
+
expect(mergeAdjacentTexts(children)).toEqual([
|
|
50
|
+
{ object: 'inline' },
|
|
51
|
+
{
|
|
52
|
+
text: '<a href="https://www.netlify.com" target="_blank">Netlify</a>',
|
|
53
|
+
marks: [],
|
|
54
|
+
},
|
|
55
|
+
{ object: 'inline' },
|
|
56
|
+
{ text: '<a href="https://www.netlify.com" target="_blank">', marks: [] },
|
|
57
|
+
{ text: 'Netlify', marks: ['b'] },
|
|
58
|
+
{
|
|
59
|
+
text: '</a><a href="https://www.netlify.com" target="_blank">',
|
|
60
|
+
marks: [],
|
|
61
|
+
},
|
|
62
|
+
{ object: 'inline' },
|
|
63
|
+
{ text: '</a>', marks: [] },
|
|
64
|
+
]);
|
|
65
|
+
});
|
|
66
|
+
});
|
|
67
|
+
});
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import unified from 'unified';
|
|
2
|
+
import u from 'unist-builder';
|
|
3
|
+
|
|
4
|
+
import remarkStripTrailingBreaks from '../remarkStripTrailingBreaks';
|
|
5
|
+
|
|
6
|
+
function process(children) {
|
|
7
|
+
const tree = u('root', children);
|
|
8
|
+
const strippedMdast = unified().use(remarkStripTrailingBreaks).runSync(tree);
|
|
9
|
+
|
|
10
|
+
return strippedMdast.children;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
describe('remarkStripTrailingBreaks', () => {
|
|
14
|
+
it('should remove trailing breaks at the end of a block', () => {
|
|
15
|
+
expect(process([u('break')])).toEqual([]);
|
|
16
|
+
expect(process([u('break'), u('text', '\n \n')])).toEqual([u('text', '\n \n')]);
|
|
17
|
+
expect(process([u('text', 'a'), u('break')])).toEqual([u('text', 'a')]);
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
it('should not remove trailing breaks that are not at the end of a block', () => {
|
|
21
|
+
expect(process([u('break'), u('text', 'a')])).toEqual([u('break'), u('text', 'a')]);
|
|
22
|
+
});
|
|
23
|
+
});
|