How to use the mdast-util-to-hast/lib/all function in mdast-util-to-hast

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 / 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))
}
github nuxt / markdown / src / handlers / link.js View on Github external
const props = {}

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

  if (url.startsWith('#') || url.match(/^https?:\/\//)) {
    props.href = url
    tagName = 'a'
  } else {
    props.to = url
    tagName = 'nuxt-link'
    props['data-press-link'] = 'true'
  }

  return h(node, tagName, props, all(h, node))
}
github nuxt / markdown / src / handlers / strong.js View on Github external
export default function strong (h, node) {
  return h(node, 'strong', all(h, node))
}
github nuxt / markdown / src / handlers / heading.js View on Github external
export default function heading (h, node) {
  let link

  const _link = node.children.find(c => c.type === 'link')
  if (_link && _link.url.startsWith('#')) {
    link = _link.url
  }

  const text = extractText(node)
  if (this.toc && text && link) {
    this.toc.push([node.depth, text, link])
  }

  return h(node, `h${node.depth}`, all(h, node))
}
github nuxt / markdown / src / handlers / table.js View on Github external
const result = []
  let pos
  let row
  let out
  let name
  let cell

  while (index--) {
    row = rows[index].children
    name = index === 0 ? 'th' : 'td'
    pos = alignLength
    out = []

    while (pos--) {
      cell = row[pos]
      out[pos] = h(cell, name, { align: align[pos] }, cell ? all(h, cell) : [])
    }

    result[index] = h(rows[index], 'tr', wrap(out, true))
  }

  return h(
    node,
    'table',
    wrap(
      [
        h(result[0].position, 'thead', wrap([result[0]], true)),
        h(
          {
            start: position.start(result[1]),
            end: position.end(result[result.length - 1])
          },

mdast-util-to-hast

mdast utility to transform to hast

MIT
Latest version published 7 months ago

Package Health Score

82 / 100
Full package analysis