@celine/bibhtml
@celine/bibhtml is a Web
Components-based referencing system for HTML documents. It aims to provide a similar user experience to
referencing in LaTeX/BibTeX
@celine/bibhtml takes significant inspiration from @citation-js/replacer, References Web Component
GitHub | MaxwellBo/ |
License | MIT |
---|---|---|---|
JSR | jsr.io/ |
Version | 1.7.0, |
Installation
Add the following script to your HTML file's <head>
element:
API
@celine/bibhtml is structured around 3 custom elements:
-
<bh-cite>
(a) -
<bh-reference>
-
<bh-bibliography>
<bh-cite><a href="#willighagen2019">[#?]</a></bh-cite> ... <bh-reference id="willighagen2019"> @article{willighagen2019, title = {Citation.js: a format-independent, modular bibliography tool for the browser and command line}, author = {Willighagen, Lars G.}, year = 2019, month = aug, keywords = {Bibliography, Javascript}, volume = 5, pages = {e214}, journal = {PeerJ Computer Science}, issn = {2376-5992}, url = {https://doi.org/10.7717/peerj-cs.214}, doi = {10.7717/peerj-cs.214} } </bh-reference> ... <bh-bibliography format="apa"> </bh-bibliography>
<bh-cite>
To cite
Citation.js<bh-cite>
element:
The <bh-cite>
element:
- Unhides the
<bh-reference>
targeted by the first inner<a>
element, and adds a backlink to itself - Replaces the first
#?
(b) contained within the first inner<a>
element with the reference number
This permits us to change the formatting of the inline citation, perhaps to use parentheses:
We may choose to forgo numbered citations entirely:
The ref
attribute assigns an explicit reference ID, and prevents the <bh-cite>
element from performing reference ID inference
(extracting the reference ID from href
attribute of the first inner <a>
element).
This allows the inner <a>
element to href
directly to the the referenced material:
The deref
attribute, achieves a similar goal by dereferencing
a citation, setting the href
attribute of the inner <a>
element to the URL associated with the reference as determined by Citation.js.
Thus, dereferenced
to link to https://doi.org/10.1145/3236774.
If we cite a missing reference
The inner text of a <bh-cite>
element is displayed unchanged when:
- The cited reference ID does not correspond to a
<bh-reference>
element with a matchingid
attribute - JavaScript is disabled
- @celine/bibhtml fails to load or execute properly
In summary:
Pattern | Citation navigates to: |
---|---|
<bh-cite> |
"#refId" |
<bh-cite ref="refId"> |
"example.com" |
<bh-cite deref> |
URL yielded by Citation.js |
<bh-reference>
Each <bh-reference>
must be tagged with an id
attribute, and contain reference information in 4 supported formats:
BibTeX
This expands to reference
Unstructured text
A <bh-reference>
can contain unstructured text. This format is useful when:
- The reference is not in a machine readable format
- The reference is malformed
- The machine readable format is not supported by @celine/bibhtml or Citation.js
Observe that the reference
DOI
This expands to reference
Wikidata
This expands to reference
<bh-bibliography>
The <bh-bibliography>
finds <bh-reference>
s and renders them in a formatted list (like at the bottom of the page).
</bh-bibliography>
has very simple calling semantics. Just:
<bh-bibliography format="apa"> </bh-bibliography>
Do not put <bh-reference>
elements inside the <bh-bibliography>
element. Everything will break.
The format
attribute sets the citation style. Currently only 1 is supported, "apa"
.
References are rendered in the order they are cited by <bh-cite>
elements, not the order they are declared in the HTML document.
Extras
<bh-cite>
has an appropriate implementation of disconnectedCallback
to remove the citation from the bibliography when the <bh-cite>
element is removed from the DOM.
References
Footnotes
-
^ The
bh-
prefix was chosen to make the use of<bh-cite>
relatively short.. -
^ I considered replacing just
?
, rather than the somewhat uglier#?
, but I worried that this would cause replacement of?
s appended to the end of uncertain dates, like2017?
.
How to cite
If you use this software, please cite it as below:
@software{Bo_bibhtml_2024, author = {Bo, Maxwell}, license = {MIT}, title = {{@celine/bibhtml}}, url = {https://maxbo.me/celine/bibhtml}, year = {2024} }