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.
@@ -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
- // Attempt to find a regex match for each plugin's pattern, and then
39
- // select the first by its occurrence in `value`. This ensures we won't
40
- // skip a plugin that occurs later in the plugin registry, but earlier
41
- // in the `value`.
42
- const [{ plugin, match } = {}] = plugins
43
- .toArray()
44
- .map(plugin => {
45
- let { pattern } = plugin;
46
- // Plugin patterns must start with a caret (^) to match the beginning of the line.
47
- // If the pattern does not start with a caret, we add it
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
- return {
54
- match: value.match(pattern),
55
- plugin,
56
- };
57
- })
58
- .filter(({ match }) => !!match)
59
- .sort((a, b) => a.match.index - b.match.index);
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
  }