unified

Project:remarkjs/remark-license

Package:remark-license@5.1.1

  1. Dependencies:3·Dependents:8
  2. remark plugin to add a license section to your readme
  1. remark 181
  2. unified 135
  3. plugin 123
  4. markdown 102
  5. mdast 69
  6. remark-plugin 65
  7. text 13
  8. plain 4

remark-license

Build Coverage Downloads Size Sponsors Backers Chat

remark plugin to add a license section to your readme.

Install

npm:

npm install remark-license

Use

Say we have the following file, example.md:

## License

Something nondescript.

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

var fs = require('fs')
var remark = require('remark')
var license = require('remark-license')

remark()
  .use(license)
  .process(fs.readFileSync('example.md'), function(err, file) {
    if (err) throw err
    console.log(String(file))
  })

Now, running node example yields:

## License

[MIT](LICENSE) © [Titus Wormer](https://wooorm.com)

API

remark().use(license[, options])

Plugin to add a license section to your readme. Adds content to the heading containing /^licen[cs]e$/i. Replaces the original content of that section. Does nothing when no heading is found. Does nothing when the processed file is the license file (such for a license heading in license.md).

options
options.name

License holder (string, optional). Detected from the package.json in the current working directory, supporting both object and string format of author. Throws when neither given nor detected.

options.license

SPDX identifier (string, optional). Detected from the license field in the package.json in the current working directory. Deprecated license objects are not supported. Throws when neither given nor detected.

options.file

File name of license file (string, optional). Detected from the files in the current working directory, in which case the first file matching /^licen[cs]e(?=$|\.)/i is used. If there is no given or found license file, but options.license is a known SPDX identifier, the URL to the license on spdx.org is used.

options.url

URL to license holder (string, optional). Detected from the package.json in the current working directory, supporting both object and string format of author. http:// is prepended if url starts without HTTP or HTTPS protocol.

options.ignoreFinalDefinitions

Ignore final definitions otherwise in the section (boolean, default: true).

Detection

Detection of package.json and files in the current working directory is based on the current working directory as set on the given vfile.

If you want to set the cwd yourself (the default is process.cwd()), you can pass in a vfile or vfile options to .process like so:

var fs = require('fs')
var path = require('path')
var remark = require('remark')
var license = require('remark-license')

remark()
  .use(license)
  .process(
    {
      cwd: path.join('.', 'some', 'path', 'to', 'a', 'directory'),
      contents: fs.readFileSync('example.md')
    },
    function(err, file) {
      if (err) throw err
      console.log(String(file))
    }
  )

Security

options.url (or author.url in package.json) is used and injected into the tree when it’s given or found. This could open you up to a cross-site scripting (XSS) attack if you pass user provided content in or store user provided content in package.json.

This may become a problem if the Markdown later transformed to rehype (hast) or opened in an unsafe Markdown viewer.

Contribute

See contributing.md in remarkjs/.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, organization, or community you agree to abide by its terms.

License

MIT © Titus Wormer