Skip to content

Commit e212cc9

Browse files
committed
make citations work for single chapter preview
1 parent c9d8ea7 commit e212cc9

File tree

9 files changed

+52
-53
lines changed

9 files changed

+52
-53
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@
66
/examples/figures/
77
/site/doc/
88
/site/_footer.md
9+
/docs/packages.bib

DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Package: litedown
22
Type: Package
33
Title: A Lightweight Version of R Markdown
4-
Version: 0.5.15
4+
Version: 0.5.16
55
Authors@R: c(
66
person("Yihui", "Xie", role = c("aut", "cre"), email = "xie@yihui.name", comment = c(ORCID = "0000-0003-0645-5666", URL = "https://yihui.org")),
77
person("Tim", "Taylor", role = "ctb", comment = c(ORCID = "0000-0002-8587-7113")),

R/mark.R

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,11 @@ mark = function(input, output = NULL, text = NULL, options = NULL, meta = list()
324324
pkg_cite = yaml_field(yaml, format, 'citation_package')
325325
if (length(pkg_cite) != 1) pkg_cite = 'natbib'
326326
bib = yaml[['bibliography']]
327+
# temporarily save the bib values when previewing a book because bib may only
328+
# be specified in index.Rmd but not other chapters
329+
if (is.character(b <- .env$current_book)) {
330+
if (length(bib)) .env$bib[[b]] = bib else bib = .env$bib[[b]]
331+
}
327332
if (length(bib) == 1 && grepl(',', bib)) bib = strsplit(bib, ',\\s*')[[1]]
328333
# add [@citation] (.bib files are assumed to be under output dir)
329334
if (length(bib)) {

docs/02-fuse.Rmd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1347,7 +1347,7 @@ this `md` chunk.
13471347
You can also use `{md} the engine **inline**`.
13481348
````
13491349

1350-
### The CSS/JS engines {#engine-css}
1350+
### The CSS/JS engines {#sec:engine-css}
13511351

13521352
You can insert CSS/JS to the output via the `css`/`js` engines, e.g.,
13531353

docs/03-syntax.Rmd

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -671,8 +671,8 @@ the number and reference of the block above:
671671

672672
### Citations
673673

674-
This feature requires the R package **rbibutils**. Please make sure it is
675-
installed before using citations.
674+
This feature requires the R package **rbibutils** [@R-rbibutils]. Please make
675+
sure it is installed before using citations.
676676

677677
``` r
678678
xfun::pkg_load2("rbibutils")

docs/04-mark.Rmd

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,17 @@ included via the `<img>` tag, and their elements cannot be manipulated or
119119
styled.
120120
:::
121121

122+
When embedding `https` resources, only these elements are considered:
123+
124+
``` html
125+
<img src="..." />
126+
<link rel="stylesheet" href="...">
127+
<script src="..."></script>
128+
```
129+
130+
If an external CSS file contains `url()` resources, these resources will also be
131+
downloaded and embedded.
132+
122133
### `js_highlight`
123134

124135
Specify the JavaScript library to syntax highlight code blocks. Possible values

docs/05-assets.Rmd

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -552,6 +552,25 @@ _Anything_ on the right.
552552
:::
553553
```
554554

555+
In case you are interested in the technical detail, it's quite simple to move an
556+
element into the margin using CSS. For example, the `.side-right` class above is
557+
roughly defined as:
558+
559+
``` css
560+
.side-right {
561+
width: 200px;
562+
float: right;
563+
margin-right: -200px
564+
}
565+
```
566+
567+
That basically means the width of the element is 200px and it floats to the
568+
right. Now its right side will touch the right margin of its parent element (the
569+
article body). What we need to do next is move it further to the right by 200px
570+
(i.e., its width), which is done by the `-200px` right margin. Remember, a
571+
positive right margin in CSS moves an element to the left, and a negative right
572+
margin moves it to the right.
573+
555574
### Body elements
556575

557576
Inside the article body, you can write a few special elements.

docs/C-notes.Rmd

Lines changed: 0 additions & 36 deletions
This file was deleted.

docs/index.Rmd

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,10 @@
22
title: "litedown: R Markdown Reimagined"
33
author: "Yihui Xie"
44
date: "`{r} Sys.Date()`"
5+
bibliography: ["packages.bib"]
56
---
67

78
```{r, include = FALSE}
8-
if (packageVersion('xfun') < '0.49.7') stop(
9-
'package versions too low; please install newer versions:\n',
10-
"install.packages(c('litedown', 'xfun'), repos = 'https://yihui.r-universe.dev')"
11-
)
12-
139
options(width = 80)
1410
1511
# return an example file in fenced Div
@@ -41,6 +37,8 @@ options(width = 80)
4137
x2 = .ex(n, ext[2], ...)
4238
xfun::fenced_div(c(x1, x2), '.flex-col')
4339
}
40+
41+
xfun::pkg_bib(c('litedown', 'commonmark', 'xfun', 'rbibutils'), 'packages.bib')
4442
```
4543

4644
```{js, echo = FALSE, type = 'module'}
@@ -152,16 +150,16 @@ just want to make the HTML world a little bit better.
152150

153151
## Overview
154152

155-
The **litedown** package is an attempt to reimagine R Markdown with one primary
156-
goal—do HTML, and do it well, with the minimalism principle. Before LaTeX fans
157-
walk away in disappointment, let me quickly clarify that LaTeX output is also
158-
supported, but please do not expect anything fancy before you learn to customize
159-
LaTeX templates. Most other output formats are not supported. No Word, RTF,
160-
PowerPoint, or EPUB.
153+
The **litedown** package [@R-litedown] is an attempt to reimagine R Markdown
154+
with one primary goal—do HTML, and do it well, with the minimalism principle.
155+
Before LaTeX fans walk away in disappointment, let me quickly clarify that LaTeX
156+
output is also supported, but please do not expect anything fancy before you
157+
learn to customize LaTeX templates. Most other output formats are not supported.
158+
No Word, RTF, PowerPoint, or EPUB.
161159

162160
R Markdown is rendered via `litedown::fuse()`, which is similar to
163161
`rmarkdown::render()` and `knitr::knit()`. Markdown is rendered via
164-
`litedown::mark()`, which uses **commonmark** instead of Pandoc.
162+
`litedown::mark()`, which uses **commonmark** [@R-commonmark] instead of Pandoc.
165163

166164
The **commonmark** package follows the GFM (GitHub Flavored Markdown) spec,
167165
which can be seen as a subset of Pandoc's Markdown. Therefore the **litedown**
@@ -355,7 +353,8 @@ JavaScript, yet it is quite flexible (@chp:widgets).
355353
### Small footprint
356354

357355
Almost everything in **litedown** was written from scratch. The package is very
358-
lightweight, with only two R package dependencies: **commonmark** and **xfun**.
356+
lightweight, with only two R package dependencies: **commonmark** and **xfun**
357+
[@R-xfun].
359358

360359
It is a deliberate design choice to keep this package lightweight, to make it
361360
relatively easy to use and simple to maintain. The functions `mark()` and

0 commit comments

Comments
 (0)