@benrbray/remark-cite
TypeScript icon, indicating that this package has built-in type declarations

2.0.1-alpha.4 • Public • Published

remark-cite

license

Plugin for remark to support pandoc-style citations. Relies on micromark-extension-cite for tokenization and mdast-util-cite for converting markdown to/from abstract syntax trees.

Note that this extension only parses the input -- it is up to you to assign meaning to these citations by looking up each key in a .bibtex file or other tagged citation database.

Install

Install @benrbray/remark-cite on npm.

npm install @benrbray/remark-cite

Usage

const unified = require('unified')
const markdown = require('remark-parse')
const { citePlugin } = require('@benrbray/remark-cite');

let defaultOptions = {
	syntax: {
		// see micromark-extension-cite
		enableAltSyntax: false,
		enablePandocSyntax: true,
	},
	toMarkdown: {
		// see mdast-util-cite
		standardizeAltSyntax: false,
		enableAuthorSuppression: true,
		useNodeValue: false
	}
};

let processor = unified()
    .use(markdown)
    .use(citePlugin, {})

Running the processor on the following markdown:

[see @wadler1989, sec. 1.3; and -@hughes1990, pp.4]

Will produce the following cite node:

{
	"type": "cite",
	"value": "[see @wadler1989, sec. 1.3; and -@hughes1990, pp.4]",
	"data": {
		"citeItems": [
			{
				"prefix": "see ",
				"key": "wadler1989",
				"suffix": ", sec. 1.3"
			},{
				"prefix": " and ",
				"suppressAuthor": true,
				"key": "hughes1990",
				"suffix": ", pp.4"
			}
		]
	}
}

Configuration

For details about the syntax tree structure, see mdast-util-cite. For details about the configuration and supported syntax, see micromark-extension-cite.

Package Sidebar

Install

npm i @benrbray/remark-cite

Weekly Downloads

15

Version

2.0.1-alpha.4

License

MIT

Unpacked Size

7.04 kB

Total Files

6

Last publish

Collaborators

  • benrbray