Add: multi-line string syntax
This commit is contained in:
parent
4115705d8f
commit
3906060aef
|
@ -263,7 +263,10 @@ var usercss = (function () {
|
||||||
|
|
||||||
function parseString(state) {
|
function parseString(state) {
|
||||||
const match = state.text.slice(state.re.lastIndex).match(
|
const match = state.text.slice(state.re.lastIndex).match(
|
||||||
/^((['"])(?:\\\2|[^\n])*?\2|\w+)\s*/);
|
state.text[state.re.lastIndex] === '`' ?
|
||||||
|
/^(`(?:\\`|[\s\S])*?`)\s*/ :
|
||||||
|
/^((['"])(?:\\\2|[^\n])*?\2|\w+)\s*/
|
||||||
|
);
|
||||||
state.re.lastIndex += match[0].length;
|
state.re.lastIndex += match[0].length;
|
||||||
state.value = unquote(match[1]);
|
state.value = unquote(match[1]);
|
||||||
}
|
}
|
||||||
|
@ -318,7 +321,7 @@ var usercss = (function () {
|
||||||
state.re.lastIndex++;
|
state.re.lastIndex++;
|
||||||
eatWhitespace(state);
|
eatWhitespace(state);
|
||||||
state.value = arr;
|
state.value = arr;
|
||||||
} else if (state.text[state.re.lastIndex] === '"') {
|
} else if (state.text[state.re.lastIndex] === '"' || state.text[state.re.lastIndex] === '`') {
|
||||||
// string
|
// string
|
||||||
parseString(state);
|
parseString(state);
|
||||||
} else if (/\d/.test(state.text[state.re.lastIndex])) {
|
} else if (/\d/.test(state.text[state.re.lastIndex])) {
|
||||||
|
@ -354,9 +357,18 @@ var usercss = (function () {
|
||||||
}
|
}
|
||||||
|
|
||||||
function unquote(s) {
|
function unquote(s) {
|
||||||
const match = s.match(/^(['"])(.*)\1$/);
|
const q = s[0];
|
||||||
if (match) {
|
if (q === s[s.length - 1] && /['"`]/.test(q)) {
|
||||||
return match[2];
|
// http://www.json.org/
|
||||||
|
return s.slice(1, -1).replace(
|
||||||
|
new RegExp(`\\\\([${q}\\\\/bfnrt]|u[0-9a-fA-F]{4})`, 'g'),
|
||||||
|
s => {
|
||||||
|
if (s[1] === q) {
|
||||||
|
return q;
|
||||||
|
}
|
||||||
|
return JSON.parse(`"${s}"`);
|
||||||
|
}
|
||||||
|
);
|
||||||
}
|
}
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user