Files
website/src/components/Markdown/env.ts
T
Esteban Borai e3eff37aca fix: Safari support for PrismJS env configuration
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.
2021-05-22 01:10:07 -04:00

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();