| 1 |
## ----include = FALSE---------------------------------------------------------- |
| 2 |
knitr::opts_chunk$set( |
| 3 |
collapse = TRUE, |
| 4 |
comment = "#>" |
| 5 |
) |
| 6 |
|
| 7 |
## ----results='asis', echo = FALSE, eval = FALSE------------------------------- |
| 8 |
# # run this to update the content below |
| 9 |
# xfun::pkg_attach2("xml2") |
| 10 |
# html <- read_html("https://yihui.org/rmarkdown-cookbook/") |
| 11 |
# chapters <- xml_find_all(html, "//li[@class='chapter']") |
| 12 |
# first_level <- chapters[which(purrr::map_lgl(xml_attr(chapters, 'data-level'), ~ grepl('^\\d+$', .x)))] |
| 13 |
# titles <- xml_text(xml_find_all(first_level, "a")) |
| 14 |
# titles <- gsub("^(\\d+)", "\\1.", titles) |
| 15 |
# titles <- gsub("^(.*) \\([*])$", "\\1", titles) |
| 16 |
# url <- file.path("https://yihui.org/rmarkdown-cookbook", xml_attr(first_level, "data-path")) |
| 17 |
# formatted <- sprintf("* [%s](%s)", titles, url) |
| 18 |
# cat(formatted, sep = "\n") |
| 19 |
|