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:
- in Node.js:
res.end(labcoat(html))
- 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.
Body text.a note
↓↓
Body text.1 a note
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.
Body text (). { id: 'chomsky93', firstname: 'Noam', lastname: 'Chomsky', year: 1993, title: 'The Minimalist Program', publisher: 'MIT Press' } { … another source }
↓↓
Body text (Chomsky 1993). Chomsky, Noam. (1993). The Minimalist Program. MIT Press.
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:
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 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:
labcoatstylenewStyle
And use it in your HTML:
<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:
the captionAnd here we see .
↓↓
Figure 1 the caption And here we see Figure 1.
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>
.