An open API service indexing awesome lists of open source software.

https://github.com/trestletech/sanitizer

HTML sanitization for R
https://github.com/trestletech/sanitizer

Last synced: 4 months ago
JSON representation

HTML sanitization for R

Awesome Lists containing this project

README

        

---
output: github_document
---

```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/README-",
out.width = "100%"
)
options(tibble.print_min = 5, tibble.print_max = 5)
library(sanitizer)
```

# sanitizer

[![R build status](https://github.com/trestletech/sanitizer/workflows/R-CMD-check/badge.svg)](https://github.com/trestletech/sanitizer/actions)

Sanitize HTML in R. Here's an example of a markdown strings that includes a potentially malicious script tag. It also has a `target` attribute in the `` tag which we don't allow by default. You can see that we render the markdown to HTML and then sanitize the resultant HTML to only allow the approved tags and attributes.

```{r}
html <- paste0('


',
'Link here
something bad
')
sanitize_markdown(paste0('**hi** there ', html))
```

```{r}
sanitize_html(html)
```

```{r}
node <- xml2::read_xml(html)
san <- sanitize_node(node)
as.character(san, options=c("no_declaration"))
```