mirror of
https://github.com/Stone-Red-Code/website.git
synced 2026-09-04 17:25:59 +02:00
Fixes a RegExp validation error caused when building and executing a RegExp with LookBehind syntax on Safari. This issue causes a white screen when running `npm start` on Safari browser.
37 lines
720 B
TypeScript
37 lines
720 B
TypeScript
import Prism from "prismjs"
|
|
|
|
import type { Grammar } from "prismjs"
|
|
|
|
function supportsLookBehind() {
|
|
try {
|
|
const lookbehindRegexp = new RegExp("(?<==)(.*)");
|
|
|
|
return lookbehindRegexp.test("=hello");
|
|
} catch(e) {
|
|
return false;
|
|
}
|
|
}
|
|
|
|
function configurePrismJS() {
|
|
const config: Grammar = {
|
|
property: {
|
|
pattern: /(.*.)(?==)/,
|
|
},
|
|
operator: {
|
|
pattern: /=/
|
|
}
|
|
}
|
|
|
|
if (supportsLookBehind()) {
|
|
/* eslint-disable-next-line id-blacklist */
|
|
config.string = {
|
|
pattern: new RegExp("(?<==)(.*.)", "g"),
|
|
global: true,
|
|
}
|
|
}
|
|
|
|
Prism.languages.env = config;
|
|
}
|
|
|
|
configurePrismJS();
|