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

labcoat

v0.3.6

Published

Enhance HTML with scholarly bibliographic and annotation features.

Downloads

13

Readme

Labcoat

Enhance HTML with scholarly bibliographic and annotation features.

Use it anywhere.

Labcoat is a fast, idempotent, side-effect-free, pure function. Its output is valid HTML5. You can use it:

  1. in Node.js: res.end(labcoat(html))
  2. in the browser: document.body.innerHTML = labcoat(document.body.innerHTML)

Prefatory comment on performance

Labcoat doesn't parse HTML, find, and then manipulate elements. It transforms one markup string into another, ignoring all but a narrowly specified set of labcoat elements (of which, more in due course). The remaining material is a subregular cousin of HTML, parsing of which is virtually instant.

Benchmark: Given a 5kb document making heavy use of labcoat features, with both latin and roman numbering, and APA citations, transpilation takes ≈1 millisecond on a 2.2ghz Core i7 (node 5.x).

Install it.

npm install labcoat

<endnote> and <endnotes />

Use the <endnote> element to get reciprocally-linked end notes. Use the companion self-closing <endnotes /> element to indicate where you want the notes to appear in the transpiled HTML.

<p>Body text.<endnote>a note</endnote></p>
<endnotes />

    ↓↓

<p>Body text.<sup><a id="intext-note-1" href="#endnote-1">1</a></sup></p>
<section id="endnotes">
  <ol class="endnotes-list">
    <li id="endnote-1"><a href="#intext-note-1">a note</a></li>
  </ol>
</section>

Numbering style

Default numbering style is plain integers; provide either a latin or roman attribute, as follows: <endnotes latin />. Then, set the list-style CSS property on ol.endnotes-list to match.

<citation /> and <bibliography />

The <citation> element and the companion <bibliography> element allow the creation of linked in-text citations and a full-length, alphabetized bibliography section.

<p>Body text (<citation chomsky93 />).</p>
<bibliography>

  { id:         'chomsky93',
    firstname:  'Noam',
    lastname:   'Chomsky',
    year:       1993,
    title:      'The Minimalist Program',
    publisher:  'MIT Press' }

  { &hellip; another source }

</bibliography>

    ↓↓

<p>Body text (<cite><a href="#chomsky93">Chomsky 1993</a></cite>).</p>
<section id="bibliography">
  <ol class="bibliography-list">
    <li id="chomsky93">
      Chomsky, Noam. (1993). The Minimalist Program. MIT Press.
    </li>
  </ol>
</section>

The bibliography data format is JSON minus some of the annoying strictness of JSON (i.e., a superset of JSON). There's no need to enclose property names in quotes unless they contain symbols. There's no need to represent multiple sources as elements of an array. But strict JSON is fine, too.

MLA & APA citation styles

Labcoat includes an implementation of both APA and MLA citation standards for the following types of resources:

  • books and anthologies
  • book chapters
  • journal articles
  • conference proceedings
  • webpages
  • newspaper articles
  • magazine articles
  • lectures
  • films
  • radio/TV broadcasts

You can specify which style you want to use (APA is default) on the <bibliography> tag:

<bibliography mla>

Custom citation styles

You can easily define custom citation styles, or extend an existing style, with cite formats. Here's a basic one for a book:

AUTHOR. (YEAR). <i>TITLE</i>. LOCATION: PUBLISHER.

Examine the included APA and MLA styles to see a variety of real-life examples.

// new-style.js
export default {
  name: 'new-style',
  extends: 'apa',
  order: 'alphabetical',
  inText: <cite-format>,
  full: {
    myNewType:   <cite-format>,
    webpage:     <cite-format>,
    newspaper:   <cite-format>,
    book:        <cite-format>,
    editedBook:  <cite-format>,
    anthology:   <cite-format>,
    bookChapter: <cite-format>,
    magazine:    <cite-format>,
    journal:     <cite-format>,
    conference:  <cite-format>,
    film:        <cite-format>,
    broadcast:   <cite-format>
  }
}

Register a custom style as follows:

import labcoat from 'labcoat'
import newStyle from './new-style'

labcoat.style(newStyle)

And use it in your HTML:

<bibliography new-style>

<diagram> + <diagcaption> and <diag />

Labcoat uses <diagram> and <diagcaption> elements to create organized <figure> and <figcaption> elements; these will be automatically labeled, numbered, and ID'ed. Use the self-closing <diag /> element to create in-text references to your diagrams, as shown here:

<diagram taj-mahal>
  <img src="taj-mahal.jpg">
  <diagcaption>the caption</diagcaption>
</diagram>
<p>And here we see <diag taj-mahal />.</p>

    ↓↓

<figure class="diagram" id="figure-1" title="taj-mahal">
  <img src="taj-mahal.jpg">
  <figcaption>
    <span class="figure-label">Figure 1</span> the caption
  </figcpation>
</figure>
<p>And here we see <a class="figure-reference" href="#figure-1">Figure 1<a>.</p>

Numbering style options

The default numbering style is plain integers. You may specify otherwise by providing either a latin-diagrams or roman-diagrams attribute to the enclosing <body> element, as follows: <body latin-diagrams>.