Skip to content

Commit

Permalink
Improve handling of vignette internet access
Browse files Browse the repository at this point in the history
  • Loading branch information
k5cents committed May 4, 2021
1 parent fa0ed49 commit c65c3e1
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 21 deletions.
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# gluedown 1.0.4

* Remove `LazyData` from DESCRIPTION per new CRAN rules. Package has no data.
* The vignettes are more careful when fetching resources from the internet.

# gluedown 1.0.3

Expand Down
11 changes: 8 additions & 3 deletions cran-comments.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,14 @@

0 errors | 0 warnings | 0 notes

## Resubmission

* Remove `LazyData` from DESCRIPTION per new CRAN rules. Package has no data.
* Used `tryCatch()` when downloading data. Can run without internet connection.

<!-- links: start -->
[gh_act]: https://github.com/kiernann/gluedown/actions
[rhub_win]: https://builder.r-hub.io/status/gluedown_1.0.3.tar.gz-cbb812dfe2e74a71a53cf01505c38092
[rhub_ubu]: https://builder.r-hub.io/status/gluedown_1.0.3.tar.gz-20264fdfccb94d11ad0eb02f4f1b8dd7
[rhub_fed]: https://builder.r-hub.io/status/gluedown_1.0.3.tar.gz-d204e734f29849b7bd044c18930b8005
[rhub_win]: https://builder.r-hub.io/status/gluedown_1.0.4.tar.gz-d803fb486c644b2fbcb7d62ca5b1d405
[rhub_ubu]: https://builder.r-hub.io/status/gluedown_1.0.4.tar.gz-17912d7e2d5f46098b4ebf2755096ffd
[rhub_fed]: https://builder.r-hub.io/status/gluedown_1.0.4.tar.gz-0d4589b34c1648e58a641fcb1c1044e4
<!-- links: end -->
35 changes: 21 additions & 14 deletions vignettes/github-spec.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -381,20 +381,27 @@ I've been copy-pasting block quotes from the GFM spec in this vignette, but we
can also use `md_quote()` to grammatically create or manipulate strings and
print them as block quotes.

```{r}
```{r eval=FALSE}
read_html("https://w.wiki/A58") %>%
html_node("blockquote") %>%
html_element("blockquote") %>%
html_text(trim = TRUE) %>%
str_remove("\\[(.*)\\]") %>%
md_quote()
```

```{r echo=FALSE, results='asis'}
read_html("https://w.wiki/A58") %>%
html_node("blockquote") %>%
html_text(trim = TRUE) %>%
str_remove("\\[(.*)\\]") %>%
md_quote()
w <- "https://en.wikipedia.org/wiki/Preamble_to_the_United_States_Constitution"
x <- tryCatch(
expr = read_html(w),
error = function(e) NULL
)
if (!is.null(x)) {
x %>%
html_element("blockquote") %>%
html_text(trim = TRUE) %>%
str_remove("\\[(.*)\\]") %>%
md_quote()
}
```

```{r}
Expand Down Expand Up @@ -571,13 +578,13 @@ md_image("https://www.r-project.org/Rlogo.png", alt = "R logo")

```{r echo=FALSE, results='asis'}
tmp <- tempfile(fileext = ".png")
try <- tryCatch(
expr = download.file("https://www.r-project.org/Rlogo.png", tmp),
error = function(e) return(NULL)
)
if (!is.null(try)) {
md_image(tmp, alt = "R logo")
}
try <- tryCatch(
expr = download.file("https://www.r-project.org/Rlogo.png", tmp),
error = function(e) return(NULL)
)
if (!is.null(try)) {
md_image(tmp, alt = "R logo")
}
```

### 6.11 Disallowed Raw HTML (extension)
Expand Down
35 changes: 31 additions & 4 deletions vignettes/literal-programming.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,25 @@ the markdown standard. Using the `rvest` package, we can programmatically scrape
Gruber's blog, extract HTML paragraph tags, and convert those tags to character
vectors.

```{r markdown_desc}
```{r markdown_desc, eval=FALSE}
markdown_blog <-
read_html("https://daringfireball.net/projects/markdown/") %>%
html_nodes("p") %>%
html_elements("p") %>%
html_text()
```

```{r echo=FALSE}
x <- tryCatch(
expr = read_html("https://daringfireball.net/projects/markdown/"),
error = function(e) NULL
)
if (!is.null(x)) {
markdown_blog <- html_text(html_elements(x, "p"))
} else {
markdown_blog <- LETTERS
}
```

Gruber first explains _what_ exactly his markdown language is.

```{r quote_what, results='asis'}
Expand Down Expand Up @@ -228,14 +240,29 @@ the results of one function into the beginning of the next. By ending this
1. Remove Wikipedia's bracketed note
1. Print that vector as a markdown block quote

```{r blockquote, results='asis'}
```{r blockquote, results='asis', eval=FALSE}
read_html("https://w.wiki/A58") %>% # 1
html_node("blockquote") %>% # 2
html_element("blockquote") %>% # 2
html_text(trim = TRUE) %>% # 3
str_remove("\\[(.*)\\]") %>% # 4
md_quote() # 5
```

```{r results='asis', echo=FALSE}
w <- "https://en.wikipedia.org/wiki/Preamble_to_the_United_States_Constitution"
x <- tryCatch(
expr = read_html(w),
error = function(e) NULL
)
if (!is.null(x)) {
x %>%
html_element("blockquote") %>%
html_text(trim = TRUE) %>%
str_remove("\\[(.*)\\]") %>%
md_quote()
}
```

[pipe]: https://magrittr.tidyverse.org/reference/pipe.html

## Extensions
Expand Down

0 comments on commit c65c3e1

Please sign in to comment.