Skip to content

Commit

Permalink
make citations work for single chapter preview
Browse files Browse the repository at this point in the history
  • Loading branch information
yihui committed Feb 26, 2025
1 parent c9d8ea7 commit e212cc9
Show file tree
Hide file tree
Showing 9 changed files with 52 additions and 53 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@
/examples/figures/
/site/doc/
/site/_footer.md
/docs/packages.bib
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: litedown
Type: Package
Title: A Lightweight Version of R Markdown
Version: 0.5.15
Version: 0.5.16
Authors@R: c(
person("Yihui", "Xie", role = c("aut", "cre"), email = "[email protected]", comment = c(ORCID = "0000-0003-0645-5666", URL = "https://yihui.org")),
person("Tim", "Taylor", role = "ctb", comment = c(ORCID = "0000-0002-8587-7113")),
Expand Down
5 changes: 5 additions & 0 deletions R/mark.R
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,11 @@ mark = function(input, output = NULL, text = NULL, options = NULL, meta = list()
pkg_cite = yaml_field(yaml, format, 'citation_package')
if (length(pkg_cite) != 1) pkg_cite = 'natbib'
bib = yaml[['bibliography']]
# temporarily save the bib values when previewing a book because bib may only
# be specified in index.Rmd but not other chapters
if (is.character(b <- .env$current_book)) {
if (length(bib)) .env$bib[[b]] = bib else bib = .env$bib[[b]]
}
if (length(bib) == 1 && grepl(',', bib)) bib = strsplit(bib, ',\\s*')[[1]]
# add [@citation] (.bib files are assumed to be under output dir)
if (length(bib)) {
Expand Down
2 changes: 1 addition & 1 deletion docs/02-fuse.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -1347,7 +1347,7 @@ this `md` chunk.
You can also use `{md} the engine **inline**`.
````

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

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

Expand Down
4 changes: 2 additions & 2 deletions docs/03-syntax.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -671,8 +671,8 @@ the number and reference of the block above:

### Citations

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

``` r
xfun::pkg_load2("rbibutils")
Expand Down
11 changes: 11 additions & 0 deletions docs/04-mark.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,17 @@ included via the `<img>` tag, and their elements cannot be manipulated or
styled.
:::

When embedding `https` resources, only these elements are considered:

``` html
<img src="..." />
<link rel="stylesheet" href="...">
<script src="..."></script>
```

If an external CSS file contains `url()` resources, these resources will also be
downloaded and embedded.

### `js_highlight`

Specify the JavaScript library to syntax highlight code blocks. Possible values
Expand Down
19 changes: 19 additions & 0 deletions docs/05-assets.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -552,6 +552,25 @@ _Anything_ on the right.
:::
```

In case you are interested in the technical detail, it's quite simple to move an
element into the margin using CSS. For example, the `.side-right` class above is
roughly defined as:

``` css
.side-right {
width: 200px;
float: right;
margin-right: -200px
}
```

That basically means the width of the element is 200px and it floats to the
right. Now its right side will touch the right margin of its parent element (the
article body). What we need to do next is move it further to the right by 200px
(i.e., its width), which is done by the `-200px` right margin. Remember, a
positive right margin in CSS moves an element to the left, and a negative right
margin moves it to the right.

### Body elements

Inside the article body, you can write a few special elements.
Expand Down
36 changes: 0 additions & 36 deletions docs/C-notes.Rmd

This file was deleted.

25 changes: 12 additions & 13 deletions docs/index.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,10 @@
title: "litedown: R Markdown Reimagined"
author: "Yihui Xie"
date: "`{r} Sys.Date()`"
bibliography: ["packages.bib"]
---

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

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

## Overview

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

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

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

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

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

0 comments on commit e212cc9

Please sign in to comment.