MCPcopy
hub / github.com/remarkjs/react-markdown / transform

Function transform

lib/index.js:359–409  ·  view source on GitHub ↗

@type {BuildVisitor }

(node, index, parent)

Source from the content-addressed store, hash-verified

357
358 /** @type {BuildVisitor<Root>} */
359 function transform(node, index, parent) {
360 if (node.type === 'raw' && parent && typeof index === 'number') {
361 if (skipHtml) {
362 parent.children.splice(index, 1)
363 } else {
364 parent.children[index] = {type: 'text', value: node.value}
365 }
366
367 return index
368 }
369
370 if (node.type === 'element') {
371 /** @type {string} */
372 let key
373
374 for (key in urlAttributes) {
375 if (
376 Object.hasOwn(urlAttributes, key) &&
377 Object.hasOwn(node.properties, key)
378 ) {
379 const value = node.properties[key]
380 const test = urlAttributes[key]
381 if (test === null || test.includes(node.tagName)) {
382 node.properties[key] = urlTransform(String(value || ''), key, node)
383 }
384 }
385 }
386 }
387
388 if (node.type === 'element') {
389 let remove = allowedElements
390 ? !allowedElements.includes(node.tagName)
391 : disallowedElements
392 ? disallowedElements.includes(node.tagName)
393 : false
394
395 if (!remove && allowElement && typeof index === 'number') {
396 remove = !allowElement(node, index, parent)
397 }
398
399 if (remove && parent && typeof index === 'number') {
400 if (unwrapDisallowed && node.children) {
401 parent.children.splice(index, 1, ...node.children)
402 } else {
403 parent.children.splice(index, 1)
404 }
405
406 return index
407 }
408 }
409 }
410}
411
412/**

Callers 2

loadFunction · 0.85
transformSourceFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…