How to use the refractor/core.highlight function in refractor

To help you get started, we’ve selected a few refractor 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 ifiokjr / remirror / @remirror / extension-code-block / src / code-block-utils.ts View on Github external
const getPositionedRefractorNodes = ({ node, pos }: NodeWithPosition) => {
  let startPos = pos + 1;
  const refractorNodes = refractor.highlight(node.textContent || '', node.attrs.language || 'markup');
  function mapper(refractorNode: ParsedRefractorNode): PositionedRefractorNode {
    const from = startPos;
    const to = from + refractorNode.text.length;
    startPos = to;
    return {
      ...refractorNode,
      from,
      to,
    };
  }

  const parsedRefractorNodes = parseRefractorNodes(refractorNodes);

  return flattenArray(parsedRefractorNodes).map(mapper);
};