Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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);
};