How to use mdast-util-to-hast - 10 common examples

To help you get started, we’ve selected a few mdast-util-to-hast 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 nuxt / markdown / src / handlers / list-item.js View on Github external
export default function listItem (h, node, parent) {
  const children = node.children
  const head = children[0]
  const raw = all(h, node)
  const loose = parent ? listLoose(parent) : listItemLoose(node)
  const props = {}
  let result
  let container
  let index
  let length
  let child

  // Tight lists should not render `paragraph` nodes as `p` elements.
  if (loose) {
    result = raw
  } else {
    result = []
    length = raw.length
    index = -1
github nuxt / markdown / src / handlers / list.js View on Github external
export default function list (h, node) {
  const props = {}
  const name = node.ordered ? 'ol' : 'ul'
  let index = -1

  if (typeof node.start === 'number' && node.start !== 1) {
    props.start = node.start
  }

  const items = all(h, node)
  const length = items.length

  // Like GitHub, add a class for custom styling.
  while (++index < length) {
    if (
      items[index].properties.className &&
      items[index].properties.className.includes('task-list-item')
    ) {
      props.className = ['contains-task-list']
      break
    }
  }

  return h(node, name, props, wrap(items, true))
}
github nuxt / markdown / src / handlers / list-item.js View on Github external
container.unshift(
      h(null, 'input', {
        type: 'checkbox',
        checked: node.checked,
        disabled: true
      })
    )

    // According to github-markdown-css, this class hides bullet.
    // See: .
    props.className = ['task-list-item']
  }

  if (loose && result.length !== 0) {
    result = wrap(result, true)
  }

  return h(node, 'li', props, result)
}
github nuxt / markdown / src / handlers / list.js View on Github external
const items = all(h, node)
  const length = items.length

  // Like GitHub, add a class for custom styling.
  while (++index < length) {
    if (
      items[index].properties.className &&
      items[index].properties.className.includes('task-list-item')
    ) {
      props.className = ['contains-task-list']
      break
    }
  }

  return h(node, name, props, wrap(items, true))
}
github umijs / father-doc / packages / umi-plugin-father-doc / src / transformer / remark / rehype.ts View on Github external
function demoHandler(h, { type, lang, value, position, ...props }) {
  // split source codes & raw code for previewer
  const clonedNode = { lang, value };
  const sources = [];

  // push original source code node
  sources.push(codeHandler(h, clonedNode));

  // push transformed source code node for tsx demo (use unshift to keep jsx first)
  if (lang === 'tsx') {
    clonedNode.lang = 'jsx';
    clonedNode.value = parseText(clonedNode.value);
    sources.unshift(codeHandler(h, clonedNode));
  }

  return h(
    position,
    'div',
    {
      type: 'previewer',
      lang,
      ...props,
    },
github umijs / father-doc / packages / umi-plugin-father-doc / src / transformer / remark / rehype.ts View on Github external
function demoHandler(h, { type, lang, value, position, ...props }) {
  // split source codes & raw code for previewer
  const clonedNode = { lang, value };
  const sources = [];

  // push original source code node
  sources.push(codeHandler(h, clonedNode));

  // push transformed source code node for tsx demo (use unshift to keep jsx first)
  if (lang === 'tsx') {
    clonedNode.lang = 'jsx';
    clonedNode.value = parseText(clonedNode.value);
    sources.unshift(codeHandler(h, clonedNode));
  }

  return h(
    position,
    'div',
    {
      type: 'previewer',
      lang,
      ...props,
    },
    [
      // append raw code node
      unist('raw', value),
      // append source code nodes
      ...sources,
    ],
github mdx-js / mdx / src / react-transformer.js View on Github external
this.Compiler = node => {
    parseFrontmatter(node)

    console.log(node)

    return toHyper(h, {
      type: 'element',
      tagName: 'div',
      properties: {},
      children: toHast(node, {
        allowDangerousHTML: true,
        handlers: {
          html: (h, node, parent) => {
            console.log(parent)
            parent.type = 'element'
            parent.tagName = 'React.Fragment'
          }
        }
      }).children
    })
  }
}
github nuxt / markdown / src / handlers / link-reference.js View on Github external
export default function linkReference (h, node) {
  const def = h.definition(node.identifier)

  if (!def) {
    return revert(h, node)
  }

  const props = { href: normalize(def.url || '') }

  if (def.title !== null && def.title !== undefined) {
    props.title = def.title
  }

  return h(node, 'a', props, all(h, node))
}
github nuxt / markdown / src / handlers / delete.js View on Github external
export default function strikethrough (h, node) {
  return h(node, 'del', all(h, node))
}
github nuxt / markdown / src / handlers / paragraph.js View on Github external
export default function paragraph (h, node) {
  return h(node, 'p', all(h, node))
}

mdast-util-to-hast

mdast utility to transform to hast

MIT
Latest version published 6 months ago

Package Health Score

82 / 100
Full package analysis