UNPKG

@mintlify/scraping

Version:

Scrape documentation frameworks to Mintlify docs

32 lines 1.19 kB
import { CONTINUE, visit } from 'unist-util-visit'; export function remarkProperlyFormatEmphasis() { return function (root) { return properlyFormatEmphasis(root); }; } const spaceNode = { type: 'text', value: ' ', }; function properlyFormatEmphasis(root) { visit(root, ['emphasis', 'strong'], function (node, index, parent) { if (node.type !== 'emphasis' && node.type !== 'strong') return CONTINUE; if (node.children.length !== 1 || !node.children[0] || node.children[0].type !== 'text' || !parent || typeof index !== 'number') return CONTINUE; const child = node.children[0]; if (child.value.startsWith(' ') || child.value.endsWith(' ')) { if (index !== 0 && child.value.startsWith(' ')) parent.children.splice(index, 0, spaceNode); if (parent.children.length > index + 1 && child.value.endsWith(' ')) parent.children.splice(index + 1, 0, spaceNode); child.value = child.value.trim(); node.children[0] = child; } }); } //# sourceMappingURL=formatEmphasis.js.map