Ready to take your JavaScript development to the next level? Meet npm Enterprise - the ultimate in enterprise JavaScript. Learn more »

unist-util-source

1.0.4 • Public • Published

unist-util-source Build Status Coverage Status

Unist utility to get the source of a Node or Position.

Installation

npm:

npm install unist-util-source

Usage

Say we have the following file, example.md:

> + **[Hello](./example)**
>   world.

And our script, example.js, looks as follows:

var vfile = require('to-vfile')
var unified = require('unified')
var parse = require('remark-parse')
var source = require('unist-util-source')
 
var file = vfile.readSync('example.md')
var tree = unified()
  .use(parse)
  .parse(file)
 
var list = tree.children[0].children[0]
console.log(source(list, file))

Now, running node example yields:

+ **[Hello](./example)**
  world.

API

source(value, doc)

Parameters
  • value (Node or Position) — Value to get
  • doc (VFile or string) — Document in which value exists
Returns

string? — Source of value in file, if available.

Contribute

See contributing.md in syntax-tree/unist for ways to get started.

This organisation has a Code of Conduct. By interacting with this repository, organisation, or community you agree to abide by its terms.

License

MIT © Titus Wormer

install

npm i unist-util-source

Downloadsweekly downloads

3,040

version

1.0.4

license

MIT

homepage

github.com

repository

Gitgithub

last publish

collaborators

  • avatar
Report a vulnerability