INNER CODE UNIT · JavaScript

unwrapJsxElement

tradingview/lightweight-charts · website/plugins/docs-markdown/index.js:426

function unwrapJsxElement(node, children, outer, replacement, ctx) {
	const first = nodeOffsets(children[0]);
	const last = nodeOffsets(children[children.length - 1]);
	if (first) {
		ctx.edits.push({ start: outer[0], end: first[0], text: replacement?.before }); // opening tag + attributes
	}
	if (last) {
		ctx.edits.push({ start: last[1], end: outer[1], text: replacement?.after }); // closing tag
	}
	const nestedFrom = ctx.edits.length;
	for (const child of children) {
		collectCleanup(child, ctx);
	}
	// Content nested in a JSX block is usually indented to match the tags. Once
	// the tags are gone that indentation turns lists into nested lists and
	// paragraphs into code blocks, so it goes with them.
	if (node.type === 'mdxJsxFlowElement' && first && last) {
		collectDedentEdits(ctx, first[0], last[1], nestedFrom);

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…