X Tutup
The Wayback Machine - https://web.archive.org/web/20201016155156/https://github.com/syntax-tree/unist-util-source
Skip to content
main
Go to file
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

readme.md

unist-util-source

Build Coverage Downloads Size Sponsors Backers Chat

unist utility to get the source of a node or at a position.

Install

npm:

npm install unist-util-source

Use

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
Returns

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

Contribute

See contributing.md in syntax-tree/.github for ways to get started. See support.md for ways to get help.

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

License

MIT © Titus Wormer

You can’t perform that action at this time.
X Tutup