Skip to content

Commit

Permalink
feature: customizable bibliography header element
Browse files Browse the repository at this point in the history
  • Loading branch information
CondensedMilk7 committed Jan 30, 2023
1 parent f7de2a2 commit fc3ed6c
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 30 deletions.
7 changes: 2 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -200,11 +200,8 @@ Only `bibPath` is required.
// (choose carefully to prevent collissions with other tokens)
bibliographyMark: "[bibliography]",

// Replace bibliography title (h2)
bibliographyTitle: "Bibliography",

// Replace bibliography title (h2) classes
bibliographyTitleClasses: "bibliography-title",
// Replace bibliography title element
bibliographyTitle: '<h2 class="bibliography-title">Bibliography</h2>',

// Wrap bibliography in a div
wrapBibliography: true,
Expand Down
9 changes: 3 additions & 6 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,8 @@ const DEFAULT_OPTIONS = {
// (choose carefully to prevent collissions with other tokens)
bibliographyMark: "[bibliography]",

// Replace bibliography title (h2)
bibliographyTitle: "Bibliography",

// Replace bibliography title (h2) classes
bibliographyTitleClasses: "bibliography-title",
// Replace bibliography title element
bibliographyTitle: '<h2 class="bibliography-title">Bibliography</h2>',

// Wrap bibliography in a div
wrapBibliography: true,
Expand Down Expand Up @@ -116,4 +113,4 @@ function importBibLatex(options) {
};
}

module.exports = mdBibLatexPlugin;
module.exports = mdBibLatexPlugin;
5 changes: 2 additions & 3 deletions src/renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ function renderer(context) {
const { citeproc } = context;
const {
wrapBibliography,
bibliographyTitleClasses,
bibliographyTitle,
bibliographyContentsWrapper,
bibliographyEntryWrapper,
Expand All @@ -29,7 +28,7 @@ function renderer(context) {
rendered += '<div class="bibliography">\n';
}

rendered += `<h2 class="${bibliographyTitleClasses}">${bibliographyTitle}</h2>\n`;
rendered += bibliographyTitle + "\n";

return rendered;
}
Expand Down Expand Up @@ -86,4 +85,4 @@ function renderer(context) {

module.exports = {
renderer,
};
};
2 changes: 1 addition & 1 deletion test/fixtures/select-bibliography-custom-title.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<p>A bibliography (Cohen, 1963) is only produced for
the items cited (Susskind &#38; Hrabovsky, 2014).</p>
<div class="bibliography">
<h2 class="bibliography-title">Sources</h2>
<h1>References</h1>
<div class="bibliography-contents">
<div class="csl-entry">Cohen, P. J. (1963). The independence of the continuum hypothesis. <i>Proceedings of the National Academy of Sciences</i>, <i>50</i>(6), 1143–1148.</div>
<div class="csl-entry">Susskind, L., &#38; Hrabovsky, G. (2014). <i>Classical mechanics: the theoretical minimum</i>. New York, NY: Penguin Random House.</div>
Expand Down
17 changes: 2 additions & 15 deletions test/integration.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,23 +92,10 @@ describe("markdown-it plug-in", function () {
expect(output).to.equal(expected);
});

specify("custom classes for bibliography title", function () {
specify("custom bibliography title element", function () {
md.use(mdBiblatex, {
bibPath: __dirname + "/fixtures/bibliography.bib",
bibliographyTitleClasses: "sources",
});

const input = fixture("select-bibliography.md");
const output = md.render(input);

const expected = fixture("select-bibliography-custom-classes.html");
expect(output).to.equal(expected);
});

specify("custom bibliography title", function () {
md.use(mdBiblatex, {
bibPath: __dirname + "/fixtures/bibliography.bib",
bibliographyTitle: "Sources",
bibliographyTitle: "<h1>References</h1>",
});

const input = fixture("select-bibliography.md");
Expand Down

0 comments on commit fc3ed6c

Please sign in to comment.