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 @benrbray/remark-cite
on npm
.
npm install @benrbray/remark-cite
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"
}
]
}
}
For details about the syntax tree structure, see mdast-util-cite
. For details about the configuration and supported syntax, see micromark-extension-cite
.