Skip to content

Commit

Permalink
Use pandoc rather than distill framework for bibliography generation
Browse files Browse the repository at this point in the history
Provides support for `csl` and `nocite` as well as use of multiple bibliographies (including non-BibTeX ones). Eliminates distill framework provided mouse-over citation display, but users seem to value the Pandoc features more than this one.
  • Loading branch information
jjallaire committed Aug 25, 2020
1 parent 3da7d7a commit e8585bc
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 28 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Type: Package
Package: distill
Title: 'R Markdown' Format for Scientific and Technical Writing
Version: 0.8
Version: 0.8.1
Authors@R: c(
person("JJ", "Allaire", role = c("aut", "cre"), email = "jj@rstudio.com"),
person("Rich", "Iannone", role = c("aut")),
Expand Down
3 changes: 3 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
## distill v0.9 (Development)

* Use pandoc rather than distill framewor for bibliography generation. Provides support for `csl` and `nocite` as well as use of multiple bibliographies (including non-BibTeX ones). Eliminates distill framework provided mouse-over citation display, but users seem to value the Pandoc features more than this one.

## distill v0.8 (CRAN)

Expand Down
26 changes: 14 additions & 12 deletions R/appendices.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,19 @@
appendices_after_body_html <- function(input_file, site_config, metadata) {

# write appendixes
references <- appendix_bibliography(metadata)
updates_and_corrections <- appendix_updates_and_corrections(metadata)
creative_commons <- appendix_creative_commons(metadata)
citation <- appendix_citation(site_config, metadata)
appendix <- tags$div(class = "appendix-bottom",
references,
updates_and_corrections,
creative_commons,
citation)

# write bibliography
bibliography <- c()
if (!is.null(metadata$bibliography)) {
bibliography <- HTML(paste(c(
'<script id="distill-bibliography" type="text/bibtex">',
readLines(file.path(dirname(input_file), metadata$bibliography), warn = FALSE),
'</script>'
), collapse = "\n"))
}

# wrap in placeholder
placeholder_html("appendices", tagList(
appendix,
bibliography
appendix
))
}

Expand Down Expand Up @@ -70,6 +61,17 @@ appendix_updates_and_corrections <- function(metadata) {
}
}

appendix_bibliography <- function(metadata) {
if (!is.null(metadata$bibliography)) {
list(
tags$h3(id = "references", "References"),
tags$div(id = "references-listing")
)
} else {
NULL
}
}

appendix_creative_commons <- function(metadata) {

if (!is.null(metadata$creative_commons)) {
Expand Down
28 changes: 13 additions & 15 deletions inst/rmarkdown/templates/distill_article/resources/distill.html
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,16 @@
color: rgba(0, 0, 0, 1.0);
}

/* Citations */

d-article .citation {
color: inherit;
cursor: inherit;
}

div.hanging-indent{
margin-left: 1em; text-indent: -1em;
}


/* Tweak 1000px media break to show more text */
Expand Down Expand Up @@ -545,24 +555,9 @@
// create d-appendix
$('.d-appendix').changeElementType('d-appendix');

// create d-bibliography
var bibliography = $('<d-bibliography></d-bibliography>');
$('#distill-bibliography').wrap(bibliography);

// flag indicating that we have appendix items
var appendix = $('.appendix-bottom').children('h3').length > 0;

// replace citations with <d-cite>
$('.citation').each(function(i, val) {
appendix = true;
var cites = $(this).attr('data-cites').split(" ");
var dt_cite = $('<d-cite></d-cite>');
dt_cite.attr('key', cites.join());
$(this).replaceWith(dt_cite);
});
// remove refs
$('#refs').remove();

// replace footnotes with <d-footnote>
$('.footnote-ref').each(function(i, val) {
appendix = true;
Expand All @@ -579,6 +574,9 @@
// remove footnotes
$('.footnotes').remove();

// move refs into #references-listing
$('#references-listing').replaceWith($('#refs'));

$('h1.appendix, h2.appendix').each(function(i, val) {
$(this).changeElementType('h3');
});
Expand Down

0 comments on commit e8585bc

Please sign in to comment.