revert: don't force multiline flag for editor component patterns (#3089)
* revert: don't force multiline flag for editor component patterns refs: 338c1b68d2865a20fed851295451175b840983d4, 4839160ee6126adfbab7bfa58452560090c00737 github issues: 3088, 3086 * fix: only trim ending white spaces/line breaks when parsing shortcodes remark validates the value of the 'eat' function using a prefix match between the original value and the value provided. Trimming the start can break that validation * fix: change console log to warn
This commit is contained in:
parent
492f6f6a20
commit
c4cbae7725
@ -26,7 +26,7 @@ export default function createEditorComponent(config) {
|
|||||||
icon,
|
icon,
|
||||||
widget,
|
widget,
|
||||||
// enforce multiline flag, exclude others
|
// enforce multiline flag, exclude others
|
||||||
pattern: new RegExp(pattern, 'm'),
|
pattern,
|
||||||
fromBlock: bind(fromBlock) || (() => ({})),
|
fromBlock: bind(fromBlock) || (() => ({})),
|
||||||
toBlock: bind(toBlock) || (() => 'Plugin'),
|
toBlock: bind(toBlock) || (() => 'Plugin'),
|
||||||
toPreview: bind(toPreview) || (!widget && (bind(toBlock) || (() => 'Plugin'))),
|
toPreview: bind(toPreview) || (!widget && (bind(toBlock) || (() => 'Plugin'))),
|
||||||
|
@ -11,8 +11,14 @@ export function remarkParseShortcodes({ plugins }) {
|
|||||||
function createShortcodeTokenizer({ plugins }) {
|
function createShortcodeTokenizer({ plugins }) {
|
||||||
return function tokenizeShortcode(eat, value, silent) {
|
return function tokenizeShortcode(eat, value, silent) {
|
||||||
let match;
|
let match;
|
||||||
|
const potentialMatchValue = value.split('\n\n')[0].trimEnd();
|
||||||
const plugin = plugins.find(plugin => {
|
const plugin = plugins.find(plugin => {
|
||||||
match = value.match(plugin.pattern);
|
match = value.match(plugin.pattern);
|
||||||
|
|
||||||
|
if (!match) {
|
||||||
|
match = potentialMatchValue.match(plugin.pattern);
|
||||||
|
}
|
||||||
|
|
||||||
return !!match;
|
return !!match;
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -23,10 +29,19 @@ function createShortcodeTokenizer({ plugins }) {
|
|||||||
|
|
||||||
const shortcodeData = plugin.fromBlock(match);
|
const shortcodeData = plugin.fromBlock(match);
|
||||||
|
|
||||||
return eat(match[0])({
|
try {
|
||||||
type: 'shortcode',
|
return eat(match[0])({
|
||||||
data: { shortcode: plugin.id, shortcodeData },
|
type: 'shortcode',
|
||||||
});
|
data: { shortcode: plugin.id, shortcodeData },
|
||||||
|
});
|
||||||
|
} catch (e) {
|
||||||
|
console.warn(
|
||||||
|
`Sent invalid data to remark. Plugin: ${plugin.id}. Value: ${
|
||||||
|
match[0]
|
||||||
|
}. Data: ${JSON.stringify(shortcodeData)}`,
|
||||||
|
);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user