Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Ability to configure ignoreIllegals#68

Open
bytestream wants to merge 1 commit intowooorm:mainfrom
bytestream:ignore-illegals
Open

Ability to configure ignoreIllegals#68
bytestream wants to merge 1 commit intowooorm:mainfrom
bytestream:ignore-illegals

Conversation

@bytestream
Copy link

ignoreIllegals: true results in discrepancies between highlightAuto in lowlight and highlightAuto in highlight.js. Setting ignoreIllegals: false seems to result in better detection, and match the results from highlight.js.

For example the below was detected as ini in lowlight and typescript in highlight.js. With ignoreIllegals: false, lowlight correctly detects the language as typescript.

const toHtml = (node: Root | Root["children"][number]): string => {
  if (node.type === "text") {
    return escapeHtml(node.value);
  }

  if (node.type === "element") {
    const className = node.properties?.className;
    const classAttr =
      className && Array.isArray(className)
        ? ` class="${className.join(" ")}"`
        : "";
    const children = node.children?.map(toHtml).join("") || "";
    return `<span${classAttr}>${children}</span>`;
  }

  if ("children" in node && node.children) {
    return node.children.map(toHtml).join("");
  }

  return "";
};

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant