cboettig / knitcitations

:package: Generate citations for knitr markdown and html files
http://carlboettiger.info
Other
220 stars 28 forks source link

Request Bulleted Argument #41

Closed trinker closed 11 years ago

trinker commented 11 years ago

In some HTML5 formats the bulleted list output doesn't look as good (reveal.js). I'm proposing a bulleted argument that might operate like this (changes to bibligraphy and print_html:

bibliography <-
function (style = "markdown", .bibstyle = "JSS", ordering = c("authors", 
    "year", "title", "journal", "volume", "number", "pages", 
    "doi", "url"), sort = FALSE, bibtex = get("bibtex_data", 
    envir = knitcitations_options),  bulleted = TRUE, ...) 
{
    out <- read_cache(bibtex = bibtex)
    if (length(out) > 0) {
        if (sort) {
            ordering <- sort(names(out))
            out <- out[ordering]
        }
    }
    if (style %in% c("R", "text", "bibtex", "textVersion", "citation", 
        "LaTeX")) {
        output <- print(out, style, .bibstyle = .bibstyle, ...)
    }
    else if (style == "rdfa") {
        output <- print_rdfa(out, ordering = ordering)
        names(output) = ""
        output <- paste(unlist(output), collapse = "", sep = "")
        pretty_output <- cat(output)
    }
    else if (style == "html") {
        output <- print_html(out, ordering = ordering, bulleted = bulleted)
        names(output) = ""
        pretty_output <- cat(output)
    }
    else if (style == "markdown") {
        output <- print_markdown(out, ordering = ordering)
        names(output) = ""
        pretty_output <- cat(output)
    }
    else {
        stop("Style not recognized")
    }
    invisible(output)
}

print_html <- 
function (bib, ordering = c("authors", "year", "title", "journal", 
    "volume", "number", "pages", "doi", "uri"), bulleted = TRUE) 
{
    references <- sapply(bib, function(r) {
        title <- paste(r$title, ".", sep = "")
        authors <- paste(sapply(r$author, function(x) paste(x$given[1], 
            " ", x$family, ", ", collapse = "", sep = "")), sep = "", 
            collapse = "")
        authors <- paste(" ", authors, sep = "")
        year <- if (!is.null(r$year)) 
            paste(" (", r$year, ")", sep = "")
        journal <- if (!is.null(r$journal)) 
            paste(" <em>", r$journal, "</em>", sep = "")
        volume <- if (!is.null(r$volume)) 
            paste(" <strong>", r$volume, "</strong>", sep = "")
        number <- if (!is.null(r$number)) 
            paste(" (", r$number, ") ", sep = "")
        pgs <- if (!is.null(r$pages)) 
            strsplit(r$pages, "--")[[1]]
        spage <- if (!is.null(pgs[1])) 
            paste(" ", pgs[1], sep = "")
        epage <- if (!is.null(pgs[2])) 
            paste("-", pgs[2], sep = "")
        pages <- paste(spage, epage, sep = "")
        doi <- if (!is.null(r$doi)) 
            paste(" <a href=\"http://dx.doi.org/", r$doi, "\">", 
                r$doi, "</a>", sep = "")
        uri <- if (is.null(r$doi) && !is.null(r$url)) 
            paste(" <a href=\"", r$url, "\">", r$url, "</a>", 
                sep = "")
        bibline <- bib_format(ordering, authors, year, title, 
            journal, volume, number, pages, doi, uri, collapse = " ")
        if (bulleted) {
            paste("\n-", bibline, sep = "")
        } else {
            paste("<p>", bibline, "</p>", sep = "")
        }
    })
    paste(paste(references, collapse = "", sep = ""))
}

Then the indenting can be handled via css class like the following:

.refs {
  padding-left: 80px;
  text-indent: -35px;
}

by the user.

cboettig commented 11 years ago

beautiful. I can just paste this in of course, but perhaps you'd like to send this as a pull request?

On Thu, Jun 6, 2013 at 5:25 AM, Tyler Rinker notifications@github.comwrote:

In some HTML5 formats the bulleted list output doesn't look as good (reveal.js). I'm proposing a bulleted argument that might operate like this (changes to bibligraphy and print_html:

bibliography <- function (style = "markdown", .bibstyle = "JSS", ordering = c("authors", "year", "title", "journal", "volume", "number", "pages", "doi", "url"), sort = FALSE, bibtex = get("bibtex_data", envir = knitcitations_options), bulleted = TRUE, ...) { out <- read_cache(bibtex = bibtex) if (length(out) > 0) { if (sort) { ordering <- sort(names(out)) out <- out[ordering] } } if (style %in% c("R", "text", "bibtex", "textVersion", "citation", "LaTeX")) { output <- print(out, style, .bibstyle = .bibstyle, ...) } else if (style == "rdfa") { output <- print_rdfa(out, ordering = ordering) names(output) = "" output <- paste(unlist(output), collapse = "", sep = "") pretty_output <- cat(output) } else if (style == "html") { output <- print_html(out, ordering = ordering, bulleted = bulleted) names(output) = "" pretty_output <- cat(output) } else if (style == "markdown") { output <- print_markdown(out, ordering = ordering) names(output) = "" pretty_output <- cat(output) } else { stop("Style not recognized") } invisible(output) }

print_html <- function (bib, ordering = c("authors", "year", "title", "journal", "volume", "number", "pages", "doi", "uri"), bulleted = TRUE) { references <- sapply(bib, function(r) { title <- paste(r$title, ".", sep = "") authors <- paste(sapply(r$author, function(x) paste(x$given[1], " ", x$family, ", ", collapse = "", sep = "")), sep = "", collapse = "") authors <- paste(" ", authors, sep = "") year <- if (!is.null(r$year)) paste(" (", r$year, ")", sep = "") journal <- if (!is.null(r$journal)) paste(" ", r$journal, "", sep = "") volume <- if (!is.null(r$volume)) paste(" ", r$volume, "", sep = "") number <- if (!is.null(r$number)) paste(" (", r$number, ") ", sep = "") pgs <- if (!is.null(r$pages)) strsplit(r$pages, "--")[[1]] spage <- if (!is.null(pgs[1])) paste(" ", pgs[1], sep = "") epage <- if (!is.null(pgs[2])) paste("-", pgs[2], sep = "") pages <- paste(spage, epage, sep = "") doi <- if (!is.null(r$doi)) paste(" <a href=\"http://dx.doi.org/", r$doi, "\">", r$doi, "", sep = "") uri <- if (is.null(r$doi) && !is.null(r$url)) paste(" <a href=\"", r$url, "\">", r$url, "", sep = "") bibline <- bib_format(ordering, authors, year, title, journal, volume, number, pages, doi, uri, collapse = " ") if (bulleted) { paste("\n-", bibline, sep = "") } else { paste("

", bibline, "

", sep = "") } }) paste(paste(references, collapse = "", sep = "")) }

Then the indenting can be handled via css class like the following:

`` .refs { padding-left: 80px; text-indent: -35px; }

by the user.

— Reply to this email directly or view it on GitHubhttps://github.com/cboettig/knitcitations/issues/41 .

Carl Boettiger UC Santa Cruz http://carlboettiger.info/

trinker commented 11 years ago

If that's easier for you but I don't care either way. Just wanted to see the functionality.

On Thu, Jun 6, 2013 at 11:07 AM, Carl Boettiger notifications@github.comwrote:

beautiful. I can just paste this in of course, but perhaps you'd like to send this as a pull request?

On Thu, Jun 6, 2013 at 5:25 AM, Tyler Rinker notifications@github.comwrote:

In some HTML5 formats the bulleted list output doesn't look as good (reveal.js). I'm proposing a bulleted argument that might operate like this (changes to bibligraphy and print_html:

bibliography <- function (style = "markdown", .bibstyle = "JSS", ordering = c("authors", "year", "title", "journal", "volume", "number", "pages", "doi", "url"), sort = FALSE, bibtex = get("bibtex_data", envir = knitcitations_options), bulleted = TRUE, ...) { out <- read_cache(bibtex = bibtex) if (length(out) > 0) { if (sort) { ordering <- sort(names(out)) out <- out[ordering] } } if (style %in% c("R", "text", "bibtex", "textVersion", "citation", "LaTeX")) { output <- print(out, style, .bibstyle = .bibstyle, ...) } else if (style == "rdfa") { output <- print_rdfa(out, ordering = ordering) names(output) = "" output <- paste(unlist(output), collapse = "", sep = "") pretty_output <- cat(output) } else if (style == "html") { output <- print_html(out, ordering = ordering, bulleted = bulleted) names(output) = "" pretty_output <- cat(output) } else if (style == "markdown") { output <- print_markdown(out, ordering = ordering) names(output) = "" pretty_output <- cat(output) } else { stop("Style not recognized") } invisible(output) }

print_html <- function (bib, ordering = c("authors", "year", "title", "journal", "volume", "number", "pages", "doi", "uri"), bulleted = TRUE) { references <- sapply(bib, function(r) { title <- paste(r$title, ".", sep = "") authors <- paste(sapply(r$author, function(x) paste(x$given[1], " ", x$family, ", ", collapse = "", sep = "")), sep = "", collapse = "") authors <- paste(" ", authors, sep = "") year <- if (!is.null(r$year)) paste(" (", r$year, ")", sep = "") journal <- if (!is.null(r$journal)) paste(" ", r$journal, "", sep = "") volume <- if (!is.null(r$volume)) paste(" ", r$volume, "", sep = "") number <- if (!is.null(r$number)) paste(" (", r$number, ") ", sep = "") pgs <- if (!is.null(r$pages)) strsplit(r$pages, "--")[[1]] spage <- if (!is.null(pgs[1])) paste(" ", pgs[1], sep = "") epage <- if (!is.null(pgs[2])) paste("-", pgs[2], sep = "") pages <- paste(spage, epage, sep = "") doi <- if (!is.null(r$doi)) paste(" <a href=\"http://dx.doi.org/", r$doi, "\">", r$doi, "", sep = "") uri <- if (is.null(r$doi) && !is.null(r$url)) paste(" <a href=\"", r$url, "\">", r$url, "", sep = "") bibline <- bib_format(ordering, authors, year, title, journal, volume, number, pages, doi, uri, collapse = " ") if (bulleted) { paste("\n-", bibline, sep = "") } else { paste("

", bibline, "

", sep = "") } }) paste(paste(references, collapse = "", sep = "")) }

Then the indenting can be handled via css class like the following:

`` .refs { padding-left: 80px; text-indent: -35px; }

by the user.

— Reply to this email directly or view it on GitHub< https://github.com/cboettig/knitcitations/issues/41> .

Carl Boettiger UC Santa Cruz http://carlboettiger.info/

— Reply to this email directly or view it on GitHubhttps://github.com/cboettig/knitcitations/issues/41#issuecomment-19051598 .

cboettig commented 11 years ago

a pull request that passes R CMD CHECK with updated roxygen documentation including a bulleted example would be great...

On Thu, Jun 6, 2013 at 8:39 AM, Tyler Rinker notifications@github.comwrote:

If that's easier for you but I don't care either way. Just wanted to see the functionality.

On Thu, Jun 6, 2013 at 11:07 AM, Carl Boettiger notifications@github.comwrote:

beautiful. I can just paste this in of course, but perhaps you'd like to send this as a pull request?

On Thu, Jun 6, 2013 at 5:25 AM, Tyler Rinker notifications@github.comwrote:

In some HTML5 formats the bulleted list output doesn't look as good (reveal.js). I'm proposing a bulleted argument that might operate like this (changes to bibligraphy and print_html:

bibliography <- function (style = "markdown", .bibstyle = "JSS", ordering = c("authors", "year", "title", "journal", "volume", "number", "pages", "doi", "url"), sort = FALSE, bibtex = get("bibtex_data", envir = knitcitations_options), bulleted = TRUE, ...) { out <- read_cache(bibtex = bibtex) if (length(out) > 0) { if (sort) { ordering <- sort(names(out)) out <- out[ordering] } } if (style %in% c("R", "text", "bibtex", "textVersion", "citation", "LaTeX")) { output <- print(out, style, .bibstyle = .bibstyle, ...) } else if (style == "rdfa") { output <- print_rdfa(out, ordering = ordering) names(output) = "" output <- paste(unlist(output), collapse = "", sep = "") pretty_output <- cat(output) } else if (style == "html") { output <- print_html(out, ordering = ordering, bulleted = bulleted) names(output) = "" pretty_output <- cat(output) } else if (style == "markdown") { output <- print_markdown(out, ordering = ordering) names(output) = "" pretty_output <- cat(output) } else { stop("Style not recognized") } invisible(output) }

print_html <- function (bib, ordering = c("authors", "year", "title", "journal", "volume", "number", "pages", "doi", "uri"), bulleted = TRUE) { references <- sapply(bib, function(r) { title <- paste(r$title, ".", sep = "") authors <- paste(sapply(r$author, function(x) paste(x$given[1], " ", x$family, ", ", collapse = "", sep = "")), sep = "", collapse = "") authors <- paste(" ", authors, sep = "") year <- if (!is.null(r$year)) paste(" (", r$year, ")", sep = "") journal <- if (!is.null(r$journal)) paste(" ", r$journal, "", sep = "") volume <- if (!is.null(r$volume)) paste(" ", r$volume, "", sep = "") number <- if (!is.null(r$number)) paste(" (", r$number, ") ", sep = "") pgs <- if (!is.null(r$pages)) strsplit(r$pages, "--")[[1]] spage <- if (!is.null(pgs[1])) paste(" ", pgs[1], sep = "") epage <- if (!is.null(pgs[2])) paste("-", pgs[2], sep = "") pages <- paste(spage, epage, sep = "") doi <- if (!is.null(r$doi)) paste(" <a href=\"http://dx.doi.org/", r$doi, "\">", r$doi, "", sep = "") uri <- if (is.null(r$doi) && !is.null(r$url)) paste(" <a href=\"", r$url, "\">", r$url, "", sep = "") bibline <- bib_format(ordering, authors, year, title, journal, volume, number, pages, doi, uri, collapse = " ") if (bulleted) { paste("\n-", bibline, sep = "") } else { paste("

", bibline, "

", sep = "") } }) paste(paste(references, collapse = "", sep = "")) }

Then the indenting can be handled via css class like the following:

`` .refs { padding-left: 80px; text-indent: -35px; }

by the user.

— Reply to this email directly or view it on GitHub< https://github.com/cboettig/knitcitations/issues/41> .

Carl Boettiger UC Santa Cruz http://carlboettiger.info/

— Reply to this email directly or view it on GitHub< https://github.com/cboettig/knitcitations/issues/41#issuecomment-19051598>

.

— Reply to this email directly or view it on GitHubhttps://github.com/cboettig/knitcitations/issues/41#issuecomment-19053981 .

Carl Boettiger UC Santa Cruz http://carlboettiger.info/

cboettig commented 11 years ago

Closed by pull request #42