mirror of
https://github.com/Stone-Red-Code/website.git
synced 2026-09-07 16:06:12 +02:00
Merge pull request #403 from EstebanBorai/fix/prism-env-config-safari
Fix | Safari support for PrismJS env configuration
This commit is contained in:
@@ -1,34 +1,36 @@
|
|||||||
import Prism from "prismjs"
|
import Prism from "prismjs"
|
||||||
|
|
||||||
if (supportsLookBehind()) {
|
import type { Grammar } from "prismjs"
|
||||||
Prism.languages.env = {
|
|
||||||
property: {
|
|
||||||
pattern: /(.*.)(?==)/,
|
|
||||||
},
|
|
||||||
string: {
|
|
||||||
pattern: /(?<==)(.*.)/g,
|
|
||||||
global: true,
|
|
||||||
},
|
|
||||||
operator: {
|
|
||||||
pattern: /=/
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
Prism.languages.env = {
|
|
||||||
property: {
|
|
||||||
pattern: /(.*.)(?==)/,
|
|
||||||
},
|
|
||||||
operator: {
|
|
||||||
pattern: /=/
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
function supportsLookBehind() {
|
function supportsLookBehind() {
|
||||||
try {
|
try {
|
||||||
return /(?<==)(.*)/.test("=hello")
|
const lookbehindRegexp = new RegExp("(?<==)(.*)");
|
||||||
|
|
||||||
|
return lookbehindRegexp.test("=hello");
|
||||||
} catch(e) {
|
} catch(e) {
|
||||||
return false;
|
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();
|
||||||
|
|||||||
Reference in New Issue
Block a user