unist-util-source
    TypeScript icon, indicating that this package has built-in type declarations

    4.0.1 • Public • Published

    unist-util-source

    Build Coverage Downloads Size Sponsors Backers Chat

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

    Install

    This package is ESM only: Node 12+ is needed to use it and it must be imported instead of required.

    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:

    import {toVFile} from 'to-vfile'
    import unified from 'unified'
    import remarkParse from 'remark-parse'
    import {source} from 'unist-util-source'
    
    var file = toVFile.readSync('example.md')
    var tree = unified()
      .use(remarkParse)
      .parse(file)
    
    var strong = tree.children[0].children[0].children[0].children[0].children[0]
    console.log(source(strong, file))

    Now, running node example yields:

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

    API

    source(value, file)

    This package exports the following identifiers: source. There is no default export.

    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

    Install

    npm i unist-util-source

    DownloadsWeekly Downloads

    2,952

    Version

    4.0.1

    License

    MIT

    Unpacked Size

    8.14 kB

    Total Files

    5

    Last publish

    Collaborators

    • wooorm
    • kmck