Skip to content

Commit

Permalink
close #358: when bibliography or references is detected in the .Rmark…
Browse files Browse the repository at this point in the history
…down post, use Pandoc to convert .markdown to .markdown and process the citations during the conversion
  • Loading branch information
yihui committed Nov 5, 2020
1 parent 89c67a5 commit 3b080d0
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 4 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: blogdown
Type: Package
Title: Create Blogs and Websites with R Markdown
Version: 0.21.37
Version: 0.21.38
Authors@R: c(
person("Yihui", "Xie", role = c("aut", "cre"), email = "xie@yihui.name", comment = c(ORCID = "0000-0003-0645-5666")),
person("Beilei", "Bian", role = "ctb"),
Expand Down
2 changes: 1 addition & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

- Documented and exported the internal function `find_hugo()` to find the Hugo executable. If multiple versions of Hugo are installed, `find_hugo()` can also find a specific version of Hugo, e.g., `blogdown::find_hugo('0.25.1')`. You may use `blogdown::find_hugo('all')` to find all possible versions of Hugo currently installed.

- The file format `.Rmarkdown` supports HTML widgets now, just like the `.Rmd` format. If you are not familiar with the `.Rmarkdown` format, you may see https://bookdown.org/yihui/blogdown/output-format.html.
- The file format `.Rmarkdown` supports HTML widgets and citations now, just like the `.Rmd` format. If you are not familiar with the `.Rmarkdown` format, you may see https://bookdown.org/yihui/blogdown/output-format.html.

## MAJOR CHANGES

Expand Down
12 changes: 12 additions & 0 deletions R/render.R
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,18 @@ process_markdown = function(x, res) {
x = xfun::protect_math(x)
# remove the special comments from HTML dependencies
x = gsub('<!--/?html_preserve-->', '', x)
# render citations
if (length(grep('^(references|bibliography):($| )', x))) {
# temporary .md files to generate citations
mds = replicate(2, wd_tempfile('.md~', pattern = 'citation'))
on.exit(unlink(mds), add = TRUE)
write_utf8(x, mds[1])
rmarkdown::pandoc_convert(
mds[1], from = 'markdown', to = 'gfm+tex_math_dollars+footnotes', output = mds[2],
options = c('--atx-headers', '--wrap=preserve'), citeproc = TRUE
)
x = c(bookdown:::fetch_yaml(x), '', read_utf8(mds[2]))
}
x
}

Expand Down
4 changes: 2 additions & 2 deletions docs/01-introduction.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -192,10 +192,10 @@ Table: (\#tab:md-diff) Differences among the three document formats.
|Feature |.Rmd |.Rmarkdown |.md |
|:------------|:----|:----------|:----|
|Run R code |yes |yes |no |
|Bibliography |yes |no |no |
|Bibliography |yes |yes |no |
|Task list |maybe|yes |yes |
|MathJax |yes |maybe |maybe|
|HTML widgets |yes |no |no |
|HTML widgets |yes |yes |no |

1. You cannot execute any R code in a plain Markdown document, whereas in an R Markdown document, you can embed R code chunks (```` ```{r} ````). However, you can still embed R code in plain Markdown using the syntax for fenced code blocks ```` ```r ```` (note there are no curly braces `{}`). Such code blocks will not be executed and may be suitable for pure demonstration purposes. Below is an example of an R code chunk in R Markdown:

Expand Down

0 comments on commit 3b080d0

Please sign in to comment.