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

markdown-it-bibliography

v0.1.0

Published

Markdown-it plugin for adding bibliographies to markdown.

Downloads

10

Readme

markdown-it-bibliography

Bibliography and citation plugin for markdown-it.

Markup is somewhat similar to the pandoc definition.

Normal citation:

Here is a citation [@chomsky], one with page info (a.k.a locator) [@chomsky{p. 4}], one with a prefix [@chomsky{See}{p. 4}].

Multiple citations: [@chomsky{p. 4}; @hermanChomsky; @lafeber{Cf.}{xi}]

HTML:

<p>
  Here is a citation (Chomsky 2003), one with page info (a.k.a locator) (Chomsky
  2003, 4), one with a prefix (See Chomsky 2003, 4).
</p>
<p>
  Multiple citations: (Chomsky 2003, 4; Herman and Chomsky 1994; Cf. LaFeber
  1983, xi)
</p>
<hr class="bib-sep" />
<section class="bibliography">
  <h3>Bibliography</h3>
  <div class="csl-bib-body">
    <div class="csl-entry">
      Chomsky, Noam. 2003. <i>Necessary Illusions</i>. CBC Massey Lectures.
      House of Anansi Press.
    </div>
    <div class="csl-entry">
      Herman, Edward S., and Noam Chomsky. 1994. <i>Manufacturing Consent</i>.
      Vintage.
    </div>
    <div class="csl-entry">
      LaFeber, Walter. 1983. <i>Inevitable Revolutions</i>. Norton.
    </div>
  </div>
</section>

You can suppress the author by adding a -:

As LaFeber explained [-@lafeber{p. 84}]

It is also possible to create in-text citations by removing the brackets:

Here is a citation @chomsky, one with page info (a.k.a locator) @chomsky{p. 4}, one with a prefix @chomsky{See}{p. 4}.

Multiple citations: @chomsky{p. 5}; @hermanChomsky; @lafeber{Cf.}{xii}

HTML:

<p>
  Here is a citation (Chomsky 2003), one with page info (a.k.a locator) (Chomsky
  2003, 4), one with a prefix (See Chomsky 2003, 4).
</p>
<p>
  Multiple citations: Chomsky (2003, 5); Herman and Chomsky (1994); Cf. LaFeber
  (Cf. 1983, xii)
</p>
<hr class="bib-sep" />
<section class="bibliography">
  <h3>Bibliography</h3>
  <div class="csl-bib-body">
    <div class="csl-entry">
      Chomsky, Noam. 2003. <i>Necessary Illusions</i>. CBC Massey Lectures.
      House of Anansi Press.
    </div>
    <div class="csl-entry">
      Herman, Edward S., and Noam Chomsky. 1994. <i>Manufacturing Consent</i>.
      Vintage.
    </div>
    <div class="csl-entry">
      LaFeber, Walter. 1983. <i>Inevitable Revolutions</i>. Norton.
    </div>
  </div>
</section>

Install

npm install markdown-it-bibliography
# or
yarn add markdown-it-bibliography

Usage

import MdIt from "markdown-it";
import biblio from "markdown-it-bibliography";

const md = MdIt().use(biblio("path-to-bib", options));

Where path-to-bib is the path to a CSL-JSON or .bib file.

The options parameter is an optional object. The following options can be set:

| Name | Type | Default | Explanation | | ------------- | ----------------------------------------------------- | --------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------- | | style | "apa" \| "chicago" \| "mla" \| "vancouver" \| Style | "chicago" | The citation and bibliography style as defined by CSL. To get a style object, see below | | locales | { [key: string]: Locale } | An object containing locales for German, English (US and GB), Spanish, and French | The locales for languages used, as defined by CSL. To get such objects, see below | | lang | string \| undefined | undefined | The language to use as default | | defaultLocale | string \| undefined | en-US | The default language to use for locator parsing |

Locator Parsing

The postnote of a citation is parsed to detect the locator, i.e., the page/chapter/etc. number, and the actual suffix. Here, we take a cue from BibLatex and parse the following things as locators:

  • 25
  • vii
  • XIV
  • 34--38
  • 185/86
  • XI & XV
  • 3, 5, 7
  • vii-x; 5, 7

The locator has to be the first thing in the postnote.

A locator can contain a label, e.g., p. xvi or ch. 5. Possible locators are taken from the locale object of the current item's language (or the defaultLocale if there is no current language).

XML Parsing

To get style or locale objects, it is best to parse the XML files found in the CSL styles repo and the CSL locales repo. For this use the parseXml function like this:

import MdIt from "markdown-it";
import biblio, { parseXml } from "markdown-it-bibliography";

const myCustomLocale = parseXml(/* some xml string */);

const md = MdIt().use(
  biblio("path-to-bib", {
    locales: {
      "en-US": myCustomLocale,
    },
  }),
);