 # Rehype-Citation [](https://GitHub.com/timlrx/rehype-citation/stargazers/) [](https://GitHub.com/timlrx/rehype-citation/network/) [](https://twitter.com/timlrxx) [](https://github.com/sponsors/timlrx) [](https://zenodo.org/doi/10.5281/zenodo.10004327) [rehype](https://github.com/wooorm/rehype) plugin to nicely format citations in markdown documents and insert bibliography in html format. It is meant to be used as a server side plugin and neatly integrates [citeproc-js](https://github.com/Juris-M/citeproc-js) and [citation-js](https://github.com/citation-js/citation-js) within the remark-rehype ecosystem. Parsing of citations and all the wonderful regexes are adapted from [Zettlr](https://github.com/Zettlr/Zettlr). It supports both normal citations (such as [@foo]) and in-text citation (such as @foo), as well as author-date, numerical, and note styles. Note styles is only compatible with Github Formatted Markdown (GFM). It is recommended to run `remark-gfm` before `rehype-citation` to ensure all footnote elements are correctly formatted. API and options follows very closely to [Rmarkdown](https://bookdown.org/yihui/rmarkdown-cookbook/bibliography.html) and [Pandoc](https://pandoc.org/MANUAL.html#citations) ## Examples - [Citations with Bibliography](https://rehype-citation.netlify.app) - [Suppress Bibliography](https://rehype-citation.netlify.app/suppress-bibliography) - [Custom CSL](https://rehype-citation.netlify.app/custom-csl) - [Footnote style](https://rehype-citation.netlify.app/footnote-style) - [Link Citations](https://rehype-citation.netlify.app/link-citations) ## Installation This package is [ESM only](https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c): Node 12+ is needed to use it and it must be `import`ed instead of `require`d. ```js npm install rehype-citation ``` ## Usage If you are using the plugin in a node environment, import from `rehype-citation/node`. For browser environments, import from `rehype-citation/browser`. The following files are exported: `generator`, generator function. Can be used to generate a rehype citation plugin. Takes in a citation-js `Cite` class. `cite`, a citation-js `Cite` instance. Add your own CSL / locales before passing in to the plugin generator . `rehype-citation`, re-exports the above 2 packages with a pre-configured `rehype-citation` plugin ready to use. Importing from `rehype-citation` directs to this file. Use this package [as a rehype plugin](https://github.com/rehypejs/rehype/blob/master/doc/plugins.md#using-plugins). Some examples of how you might do that: ```js import rehype from 'rehype' import rehypeCitation from 'rehype-citation' rehype().use(rehypeCitation).process(/* some html */) ``` ## Sample markdown to HTML output Input: ```md My markdown text [@Nash1950] ``` HTML Output: ```html