decap-cms-widget-markdown 3.7.0 → 3.9.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 +16 -0
- package/dist/decap-cms-widget-markdown.js +4 -4
- package/dist/decap-cms-widget-markdown.js.LICENSE.txt +0 -2
- package/dist/decap-cms-widget-markdown.js.map +1 -1
- package/dist/esm/MarkdownControl/index.js +14 -2
- package/dist/esm/MarkdownControl/plugins/html/withHtml.js +45 -10
- package/dist/esm/MarkdownControl/plugins/shortcodes/insertShortcode.js +1 -1
- package/dist/esm/MarkdownControl/renderers.js +19 -19
- package/dist/esm/MarkdownPreview.js +2 -1
- package/dist/esm/serializers/index.js +19 -3
- package/dist/esm/serializers/remarkRehypeShortcodes.js +26 -3
- package/dist/esm/serializers/remarkShortcodes.js +18 -41
- package/package.json +4 -3
- package/src/MarkdownControl/index.js +13 -2
- package/src/MarkdownControl/plugins/html/__tests__/withHtml.spec.js +67 -0
- package/src/MarkdownControl/plugins/html/withHtml.js +51 -4
- package/src/MarkdownControl/plugins/shortcodes/insertShortcode.js +1 -2
- package/src/MarkdownControl/renderers.js +1 -1
- package/src/MarkdownPreview.js +3 -1
- package/src/__tests__/renderer.spec.js +10 -0
- package/src/serializers/__tests__/index.spec.js +15 -0
- package/src/serializers/__tests__/remarkShortcodes.spec.js +16 -38
- package/src/serializers/index.js +19 -1
- package/src/serializers/remarkRehypeShortcodes.js +32 -3
- package/src/serializers/remarkShortcodes.js +29 -46
|
@@ -8,57 +8,40 @@ export function remarkParseShortcodes({ plugins }) {
|
|
|
8
8
|
methods.unshift('shortcode');
|
|
9
9
|
}
|
|
10
10
|
|
|
11
|
-
export function getLinesWithOffsets(value) {
|
|
12
|
-
const SEPARATOR = '\n\n';
|
|
13
|
-
const splitted = value.split(SEPARATOR);
|
|
14
|
-
const trimmedLines = splitted
|
|
15
|
-
.reduce(
|
|
16
|
-
(acc, line) => {
|
|
17
|
-
const { start: previousLineStart, originalLength: previousLineOriginalLength } =
|
|
18
|
-
acc[acc.length - 1];
|
|
19
|
-
|
|
20
|
-
return [
|
|
21
|
-
...acc,
|
|
22
|
-
{
|
|
23
|
-
line: line.trimEnd(),
|
|
24
|
-
start: previousLineStart + previousLineOriginalLength + SEPARATOR.length,
|
|
25
|
-
originalLength: line.length,
|
|
26
|
-
},
|
|
27
|
-
];
|
|
28
|
-
},
|
|
29
|
-
[{ start: -SEPARATOR.length, originalLength: 0 }],
|
|
30
|
-
)
|
|
31
|
-
.slice(1)
|
|
32
|
-
.map(({ line, start }) => ({ line, start }));
|
|
33
|
-
return trimmedLines;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
11
|
function createShortcodeTokenizer({ plugins }) {
|
|
12
|
+
plugins.forEach(plugin => {
|
|
13
|
+
if (plugin.pattern.flags.includes('m')) {
|
|
14
|
+
console.warn(
|
|
15
|
+
`Invalid RegExp: editor component '${plugin.id}' must not use the multiline flag in its pattern.`,
|
|
16
|
+
);
|
|
17
|
+
}
|
|
18
|
+
});
|
|
37
19
|
return function tokenizeShortcode(eat, value, silent) {
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
// to ensure that remark consumes only the shortcode, without any leading text.
|
|
49
|
-
if (!pattern.source.startsWith('^')) {
|
|
50
|
-
pattern = new RegExp(`^${pattern.source}`, pattern.flags);
|
|
51
|
-
}
|
|
20
|
+
let match;
|
|
21
|
+
const potentialMatchValue = value.split('\n\n')[0].trimEnd();
|
|
22
|
+
const plugin = plugins.find(plugin => {
|
|
23
|
+
let { pattern } = plugin;
|
|
24
|
+
// Plugin patterns must start with a caret (^) to match the beginning of the block.
|
|
25
|
+
// If the pattern does not start with a caret, we add it
|
|
26
|
+
// to ensure that remark consumes only the shortcode, without any leading text.
|
|
27
|
+
if (!pattern.source.startsWith('^')) {
|
|
28
|
+
pattern = new RegExp(`^${pattern.source}`, pattern.flags);
|
|
29
|
+
}
|
|
52
30
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
31
|
+
match = value.match(pattern);
|
|
32
|
+
if (!match) {
|
|
33
|
+
match = potentialMatchValue.match(pattern);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
return !!match;
|
|
37
|
+
});
|
|
60
38
|
|
|
61
39
|
if (match) {
|
|
40
|
+
if (match.index > 0) {
|
|
41
|
+
console.warn(
|
|
42
|
+
`Invalid RegExp: editor component '${plugin.id}' must match from the beginning of the block.`,
|
|
43
|
+
);
|
|
44
|
+
}
|
|
62
45
|
if (silent) {
|
|
63
46
|
return true;
|
|
64
47
|
}
|