Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function parseToken(token, counter) {
if (token === "\n") {
counter.current = 0;
return token;
} else if (typeof token === "string" && token.includes("\n")) {
const [left, ...rest] = token.split("\n");
const right = rest.join("\n");
const tokens = addCustomTokens([left, "\n", right], counter);
return tokens;
} else if (typeof token === "string" && !token.trim()) {
// whitespace
return token;
} else if (typeof token === "string") {
counter.current++;
return new Prism.Token(
"free-text",
token,
["token-" + counter.current, "token-leaf"],
token
);
} else if (Prism.util.type(token.content) === "Array") {
token.content = addCustomTokens(token.content, counter);
return token;
} else {
counter.current++;
const aliases =
Prism.util.type(token.alias) === "Array" ? token.alias : [token.alias];
aliases.push("token-" + counter.current, "token-leaf");
token.alias = aliases;
return token;
}
.map(token => {
if (typeof token === 'string') {
return new Prism.Token('span', token.replace('\n', ''));
}
return token;
});