npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

rehype-citation

v2.2.2

Published

rehype plugin to add citation and bibliography from bibtex files

Downloads

63,499

Readme

rehype citation

Rehype-Citation

GitHub Repo stars GitHub forks Twitter URL Sponsor DOI

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 and citation-js within the remark-rehype ecosystem. Parsing of citations and all the wonderful regexes are adapted from 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 and Pandoc

Examples

Installation

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

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.

Some examples of how you might do that:

import rehype from 'rehype'
import rehypeCitation from 'rehype-citation'

rehype().use(rehypeCitation).process(/* some html */)

Sample markdown to HTML output

Input:

My markdown text [@Nash1950]

HTML Output:

<div>My markdown text (Nash, 1950)</div>
<div id="refs" class="references csl-bib-body">
  <div class="csl-entry">
    Nash, J. (1950). Equilibrium points in n-person games.
    <i>Proceedings of the National Academy of Sciences</i>, <i>36</i>(1), 48–49.
  </div>
</div>

Generating your own remark citation plugins

The default plugin comes configured with the en-US locale and the following CSL styles: apa, vancouver, harvard1, chicago and mla.

Use the generator function to customize your own remark-citation plugin and add your own CSL styles or locales.

import Cite from 'rehype-citation/cite'
import rehypeCitationGenerator from 'rehype-citation/generator'
import myStyle from '../style'
import myLocale from '../locale'

const config = Cite.plugins.config.get('@csl')
config.templates.add('mystyle', myStyle)
config.locales.add('myLocale', myLocale)

const rehypeCitation = rehypeCitationGenerator(Cite)

API

rehype().use(rehypeCitation, [options])

If no bibliography file is passed, the plugin will be skipped.

options

options.bibliography

Type: string|string[].

By default, if no bibliography file is passed, the plugin will be skipped.

Name or path to Bibtex, CSL-JSON or CFF file. If multiple files are provided, they will be merged.

options.path

Type: string. Default: process.cwd().

Required, path to file. Will be joined with options.bibliography and options.csl, if provided.

options.csl

Type: 'apa'|'vancouver'|'harvard1'|'chicago'|'mla'|string. Default: apa.

For the main rehypeCitation plugin, one of 'apa', 'vancouver', 'harvard1', 'chicago', 'mla'. A local file path or URL to a valid CSL file is also accepted. Can also be specified as a frontmatter option in the markdown file to override the default.

options.lang

Type: string. Default: en-US.

Locale to use in formatting citations. Defaults to en-US. A local file path or URL to a valid locale file is also accepted.

options.suppressBibliography

Type: boolean. Default: false.

Suppress bibliography? By default, biliography is inserted after the entire markdown file. If the file contains [^ref], the biliography will be inserted there instead.

options.noCite

Type: string[].

Citation IDs (@item1) to include in the bibliography even if they are not cited in the document. Can also be specified as a frontmatter option in the markdown file.

options.inlineClass

Type: string[].

Array of classes for inline citations.

options.inlineBibClass

Type: string[].

Array of classes for inline bibliography. Leave empty to disable inline bibliography.

options.linkCitations

Type: boolean. Default: false.

If true, citations will be hyperlinked to the corresponding bibliography entries (for author-date and numeric styles only).