How to use the prismjs.Token function in prismjs

To help you get started, we’ve selected a few prismjs examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github pomber / code-surfer / packages / code-surfer / src / highlighter.js View on Github external
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;
  }
github wowlusitong / re-editor / packages / core / src / scripts / components / ReEditor.js View on Github external
.map(token => {
        if (typeof token === 'string') {
          return new Prism.Token('span', token.replace('\n', ''));
        }
        return token;
      });