Browse Source

basic error checking & tests

master
boB Rudis 6 years ago
parent
commit
51f69ca33f
No known key found for this signature in database GPG Key ID: 1D7529BE14E2BBA9
  1. 5
      DESCRIPTION
  2. 7
      NEWS.md
  3. 7
      README.Rmd
  4. 4
      README.md
  5. 2
      src/Makevars
  6. 12
      src/htmltidy.cpp
  7. 3
      tests/testthat/test-htmltidy.R

5
DESCRIPTION

@ -1,6 +1,6 @@
Package: htmltidy
Title: Clean up gnarly HTML/XML
Version: 0.0.0.9000
Version: 0.1.0.9000
Authors@R: c(person("Bob", "Rudis", email = "bob@rudis.net", role = c("aut", "cre")))
Description: Clean up gnarly HTML/XML
Depends:
@ -8,7 +8,8 @@ Depends:
License: AGPL + file LICENSE
LazyData: true
Suggests:
testthat
testthat,
xml2
LinkingTo: Rcpp
Imports:
Rcpp

7
NEWS.md

@ -0,0 +1,7 @@
# htmltidy 0.1.0.9000
* Added a `NEWS.md` file to track changes to the package.
* Added Debian & Ubuntu compatibility
* Added basic error checking
* Added basic test harness

7
README.Rmd

@ -8,6 +8,9 @@ output: rmarkdown::github_document
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
message = FALSE,
warning = FALSE,
error = FALSE,
fig.retina=2,
fig.path = "README-"
)
@ -19,7 +22,7 @@ Inspired by [this SO question](http://stackoverflow.com/questions/37061873/ident
NOTE: Requires [`libtidy`](http://www.html-tidy.org/) and presently is super-basic (no way to set options and pretty much only does HTML)
`brew install tidy-html5` on OS X to get this to work. You'll have to do a bit more leg-work to get it to work on linux (`apt-get install libtidy-dev` on Ubuntu sticks the library in a `tidy` subdir off `/usr/lib` and I don't have a `configure` script setup yet).
You'll need to first do a `brew install tidy-html5` on MacOS or `apt-get install libtidy-dev` on Ubuntu/Debian to get this to work.
**SEEKING COLLABORATORS**
@ -38,7 +41,7 @@ The following functions are implemented:
devtools::install_github("hrbrmstr/htmltidy")
```
```{r echo=FALSE, message=FALSE, warning=FALSE, error=FALSE}
```{r echo=FALSE}
options(width=120)
```

4
README.md

@ -6,7 +6,7 @@ Inspired by [this SO question](http://stackoverflow.com/questions/37061873/ident
NOTE: Requires [`libtidy`](http://www.html-tidy.org/) and presently is super-basic (no way to set options and pretty much only does HTML)
`brew install tidy-html5` on OS X to get this to work. You'll have to do a bit more leg-work to get it to work on linux (`apt-get install libtidy-dev` on Ubuntu sticks the library in a `tidy` subdir off `/usr/lib` and I don't have a `configure` script setup yet).
You'll need to first do a `brew install tidy-html5` on MacOS or `apt-get install libtidy-dev` on Ubuntu/Debian to get this to work.
**SEEKING COLLABORATORS**
@ -32,7 +32,7 @@ library(htmltidy)
# current verison
packageVersion("htmltidy")
#> [1] '0.0.0.9000'
#> [1] '0.1.0.9000'
cat(tidy("<b><p><a href='http://google.com'>google &gt</a></p></b>"))
#> <!DOCTYPE html>

2
src/Makevars

@ -1,3 +1 @@
#PKG_CXXFLAGS=-I/usr/local/include -I/usr/include -I/opt/include -I/usr/include/tidy -I/usr/local/include/tidy
#PKG_CPPFLAGS=-I/usr/local/include -I/usr/include -I/opt/include -I/usr/include/tidy -I/usr/local/include/tidy
PKG_LIBS=-ltidy

12
src/htmltidy.cpp

@ -32,16 +32,28 @@ std::string tidy(std::string source) {
ok = tidyOptSetBool(tdoc, TidyXhtmlOut, yes);
if (ok == no) Rcpp::stop("Error setting TidyHTML options");
rc = tidySetErrorBuffer(tdoc, &errbuf);
if (rc<0) Rcpp::stop("Error setting TidyHTML error buffer");
rc = tidyParseString(tdoc, source.c_str());
if (rc<0) Rcpp::stop("Error parsing source document");
rc = tidyCleanAndRepair(tdoc);
if (rc<0) Rcpp::stop("Error tidying source document");
rc = tidyRunDiagnostics(tdoc);
if (rc<0) Rcpp::stop("Error generating tidy diagnostics");
rc = tidySaveBuffer(tdoc, &output);
if (rc<0) Rcpp::stop("Error converting parsed document to character vector");
std::string ret = std::string(reinterpret_cast<const char*>(output.bp));
tidyBufFree(&output);

3
tests/testthat/test-htmltidy.R

@ -1,6 +1,7 @@
context("basic functionality")
test_that("we can do something", {
#expect_that(some_function(), is_a("data.frame"))
expect_that(nchar(tidy("<b><p><a href='http://google.com'>google &gt</a></p></b>")),
equals(256))
})

Loading…
Cancel
Save