Workaround for old Safari
This commit is contained in:
parent
cf28d6653c
commit
41f25edb15
|
@ -1629,14 +1629,30 @@ export function highlightRegex(regexStr) {
|
||||||
regexStr = escapeHtml(regexStr);
|
regexStr = escapeHtml(regexStr);
|
||||||
|
|
||||||
// Patterns that we want to highlight only if they are not escaped
|
// Patterns that we want to highlight only if they are not escaped
|
||||||
const patterns = {
|
function getPatterns() {
|
||||||
brackets: /(?<!\\)\[.*?\]/g, // Non-escaped squary brackets
|
try {
|
||||||
quantifiers: /(?<!\\)[*+?{}]/g, // Non-escaped quantifiers
|
return {
|
||||||
operators: /(?<!\\)[|.^$()]/g, // Non-escaped operators like | and ()
|
brackets: new RegExp('(?<!\\\\)\\[.*?\\]', 'g'), // Non-escaped square brackets
|
||||||
specialChars: /\\./g,
|
quantifiers: new RegExp('(?<!\\\\)[*+?{}]', 'g'), // Non-escaped quantifiers
|
||||||
flags: /(?<=\/)([gimsuy]*)$/g, // Match trailing flags
|
operators: new RegExp('(?<!\\\\)[|.^$()]', 'g'), // Non-escaped operators like | and ()
|
||||||
delimiters: /^\/|(?<![\\<])\//g, // Match leading or trailing delimiters
|
specialChars: new RegExp('\\\\.', 'g'),
|
||||||
};
|
flags: new RegExp('(?<=\\/)([gimsuy]*)$', 'g'), // Match trailing flags
|
||||||
|
delimiters: new RegExp('^\\/|(?<![\\\\<])\\/', 'g'), // Match leading or trailing delimiters
|
||||||
|
};
|
||||||
|
|
||||||
|
} catch (error) {
|
||||||
|
return {
|
||||||
|
brackets: new RegExp('(\\\\)?\\[.*?\\]', 'g'), // Non-escaped square brackets
|
||||||
|
quantifiers: new RegExp('(\\\\)?[*+?{}]', 'g'), // Non-escaped quantifiers
|
||||||
|
operators: new RegExp('(\\\\)?[|.^$()]', 'g'), // Non-escaped operators like | and ()
|
||||||
|
specialChars: new RegExp('\\\\.', 'g'),
|
||||||
|
flags: new RegExp('/([gimsuy]*)$', 'g'), // Match trailing flags
|
||||||
|
delimiters: new RegExp('^/|[^\\\\](/)', 'g'), // Match leading or trailing delimiters
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const patterns = getPatterns();
|
||||||
|
|
||||||
// Function to replace each pattern with a highlighted HTML span
|
// Function to replace each pattern with a highlighted HTML span
|
||||||
const wrapPattern = (pattern, className) => {
|
const wrapPattern = (pattern, className) => {
|
||||||
|
|
Loading…
Reference in New Issue