How to use @mdx-js/util - 8 common examples

To help you get started, we’ve selected a few @mdx-js/util examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github mdx-js / mdx / packages / mdx / mdx-hast-to-jsx.js View on Github external
parentNode.tagName ? ` parentName="${parentNode.tagName}"` : ''
    }${props ? ` {...${props}}` : ''}>${children}`
  }

  // Wraps text nodes inside template string, so that we don't run into escaping issues.
  if (node.type === 'text') {
    // Don't wrap newlines unless specifically instructed to by the flag,
    // to avoid issues like React warnings caused by text nodes in tables.
    const shouldPreserveNewlines =
      preserveNewlines || parentNode.tagName === 'p'

    if (node.value === '\n' && !shouldPreserveNewlines) {
      return node.value
    }

    return toTemplateLiteral(node.value)
  }

  if (node.type === 'comment') {
    return `{/*${node.value}*/}`
  }

  if (node.type === 'import' || node.type === 'export' || node.type === 'jsx') {
    return node.value
  }
}
github mdx-js / mdx / packages / mdx / mdx-hast-to-jsx.js View on Github external
(properties, [key, value]) =>
        Object.assign({}, properties, {
          [paramCaseRe.test(key) ? paramCase(key) : key]: value
        }),
      {}
github mdx-js / mdx / packages / babel-plugin-html-attributes-to-jsx / index.js View on Github external
JSXAttribute(node) {
    if (node.node.name.name in TRANSLATIONS) {
      node.node.name.name = TRANSLATIONS[node.node.name.name]
    } else if (node.node.name.name === `props`) {
      node.traverse(propsKeysVisitor)
    } else if (
      node.node.name.name.startsWith(`data`) ||
      node.node.name.name.startsWith(`aria`)
    ) {
      const CAMEL_CASE_REGEX = /^(aria[A-Z])|(data[A-Z])/
      if (CAMEL_CASE_REGEX.test(node.node.name.name)) {
        node.node.name.name = camelCase(node.node.name.name)
      }
    } else if (
      node.node.name.name in ARRAY_TO_STRING &&
      node.node.value.type === 'JSXExpressionContainer' &&
      node.node.value.expression.type === 'ArrayExpression'
    ) {
      node.node.value = t.stringLiteral(
        node.node.value.expression.elements.map(el => el.value).join(' ')
      )
    }

    if (
      node.node.name.name === `style` &&
      node.node.value.type === `StringLiteral`
    ) {
      let styleArray = []
github mdx-js / mdx / packages / mdx / md-ast-to-mdx-ast.js View on Github external
visit(tree, 'jsx', node => {
    if (isComment(node.value)) {
      node.type = 'comment'
      node.value = getCommentContents(node.value)
    }
  })
github mdx-js / mdx / packages / mdx / md-ast-to-mdx-ast.js View on Github external
visit(tree, 'jsx', node => {
    if (isComment(node.value)) {
      node.type = 'comment'
      node.value = getCommentContents(node.value)
    }
  })
github mdx-js / mdx / packages / remark-mdx / index.js View on Github external
function tokenizeEsSyntax(eat, value) {
  const index = value.indexOf(EMPTY_NEWLINE)
  const subvalue = index !== -1 ? value.slice(0, index) : value

  if (isImportOrExport(subvalue)) {
    const nodes = extractImportsAndExports(subvalue, this.file)
    nodes.map(node => eat(node.value)(node))
  }
}
github mdx-js / mdx / packages / remark-mdx / index.js View on Github external
function tokenizeEsSyntaxLocator(value, _fromIndex) {
  return isImportOrExport(value) ? -1 : 1
}
github mdx-js / mdx / packages / babel-plugin-apply-mdx-type-props / index.js View on Github external
JSXOpeningElement(path) {
            const jsxName = path.node.name.name

            if (startsWithCapitalLetter(jsxName)) {
              componentNames.push(jsxName)

              path.node.attributes.push(
                t.jSXAttribute(
                  t.jSXIdentifier(`mdxType`),
                  t.stringLiteral(jsxName)
                )
              )
            }
          }
        }

@mdx-js/util

Deprecated: this package is no longer maintained.

MIT
Latest version published 2 months ago

Package Health Score

69 / 100
Full package analysis

Similar packages