function paragraphVistor()

in site/src/buildtime/legacyImportDemoInstruction/remarkPlugin.ts [26:65]


function paragraphVistor(
  node: mdast.Paragraph,
  ancestors: mdast.Parent[],
  file
) {
  if (!(node.children.length === 1 && node.children[0].type === 'text')) return

  const text = node.children[0].value as string
  const demoPath = resolveText(text)
  if (!demoPath) return

  // parent should be the root node
  if (ancestors.length !== 1) {
    throw new Error(
      `remarkPlugin: Please use legacyImportDemoInstruction at root level of markdown!`
    )
  }

  const parent = ancestors[0] as mdast.Parent

  // insert mdx import and jsx
  // hash it to make identifer different: https://github.com/gatsbyjs/gatsby/issues/16799
  const identiferName = `legacyImportDemo_${stringHash(
    file.contents + demoPath
  )}`

  // remove instruction node and insert mdx import
  parent.children.splice(
    parent.children.indexOf(node),
    1,
    {
      type: 'import' as any,
      value: `import ${identiferName} from "${demoPath}?loadDemo"`,
    },
    {
      type: 'jsx' as any,
      value: `<DemoRenderer__LegacyDemoInstructions demoInfo={${identiferName}} />`,
    }
  )
}