How to use the unist-util-position.end function in unist-util-position

To help you get started, we’ve selected a few unist-util-position 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 remarkjs / remark-lint / packages / remark-lint-no-consecutive-blank-lines / index.js View on Github external
if (!generated(node) && children) {
      head = children[0]

      if (head && !generated(head)) {
        // Compare parent and first child.
        compare(position.start(node), position.start(head), 0)

        // Compare between each child.
        children.forEach(visitChild)

        tail = children[children.length - 1]

        // Compare parent and last child.
        if (tail !== head && !generated(tail)) {
          compare(position.end(node), position.end(tail), 1)
        }
      }
    }
  }
github vhf / remark-lint-blank-lines-1-0-2 / dist / blank-lines.js View on Github external
visit(tree, function (node, index, parent) {
    var next = parent && parent.children[index + 1];

    if (generated(node)) {
      return;
    }

    if (next && isApplicable(node) && isApplicable(next)) {
      if (node.type === 'heading' && next.type === 'heading') {
        if (position.start(next).line !== position.end(node).line + 2) {
          file.message('Incorrect number of blank lines between headings', node);
        }
      } else if (node.type === 'heading' && next.type !== 'heading') {
        if (position.start(next).line - position.end(node).line !== 2) {
          file.message('Incorrect number of blank lines between heading and section', node);
        }
      } else if (node.type === 'list') {
        if (position.start(next).line - position.end(node).line !== 3) {
          file.message('Incorrect number of blank lines between last section and next heading', node);
        }
      }
    }
  });
}
github vhf / remark-lint-blank-lines-1-0-2 / lib / blank-lines.js View on Github external
visit(tree, (node, index, parent) => {
    const next = parent && parent.children[index + 1];

    if (generated(node)) {
      return;
    }

    if (next && isApplicable(node) && isApplicable(next)) {
      if (node.type === 'heading' && next.type === 'heading') {
        if (position.start(next).line !== position.end(node).line + 2) {
          file.message('Incorrect number of blank lines between headings', node);
        }
      } else if (node.type === 'heading' && next.type !== 'heading') {
        if (position.start(next).line - position.end(node).line !== 2) {
          file.message('Incorrect number of blank lines between heading and section', node);
        }
      } else if (node.type === 'list') {
        if (position.start(next).line - position.end(node).line !== 3) {
          file.message('Incorrect number of blank lines between last section and next heading', node);
        }
      }
    }
  });
}
github remarkjs / remark-lint / packages / remark-lint-definition-case / index.js View on Github external
function validate(node) {
    var start = position.start(node).offset
    var end = position.end(node).offset
    var value

    if (!generated(node)) {
      value = contents.slice(start, end).match(label)[1]

      if (value !== value.toLowerCase()) {
        file.message(reason, node)
      }
    }
  }
}
github syntax-tree / mdast-util-to-hast / lib / index.js View on Github external
if (right.type === 'element' && data.hProperties) {
        right.properties = Object.assign({}, right.properties, data.hProperties)
      }

      if (right.children && data.hChildren) {
        right.children = data.hChildren
      }
    }

    ctx = left && left.position ? left : {position: left}

    if (!generated(ctx)) {
      right.position = {
        start: position.start(ctx),
        end: position.end(ctx)
      }
    }

    return right
  }
github remarkjs / remark-lint / packages / remark-lint-no-missing-blank-lines / index.js View on Github external
function visitor(node, index, parent) {
    var next

    if (!generated(node) && parent && (!allow || parent.type !== 'listItem')) {
      next = parent.children[index + 1]

      if (
        next &&
        types.indexOf(next.type) !== -1 &&
        position.start(next).line === position.end(node).line + 1
      ) {
        file.message(reason, next)
      }
    }
  }
}
github nuxt / markdown / src / handlers / table.js View on Github external
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])
          },
          'tbody',
          wrap(result.slice(1), true)
        )
      ],
      true
    )
  )
}
github remarkjs / remark-lint / packages / remark-lint-no-consecutive-blank-lines / index.js View on Github external
function visitChild(child, index, all) {
    var prev = all[index - 1]
    var max = 2

    if (prev && !generated(prev) && !generated(child)) {
      if (
        (prev.type === 'list' && child.type === 'list') ||
        (child.type === 'code' && prev.type === 'list' && !child.lang)
      ) {
        max++
      }

      compare(position.end(prev), position.start(child), max)
    }
  }
}

unist-util-position

unist utility to get the position of a node

MIT
Latest version published 1 year ago

Package Health Score

71 / 100
Full package analysis

Popular unist-util-position functions