diff --git a/DESCRIPTION b/DESCRIPTION index 20d6392..955a5b2 100644 --- a/DESCRIPTION +++ b/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 diff --git a/NEWS.md b/NEWS.md new file mode 100644 index 0000000..3a0f792 --- /dev/null +++ b/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 + diff --git a/README.Rmd b/README.Rmd index c3e7d1a..72db971 100644 --- a/README.Rmd +++ b/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) ``` diff --git a/README.md b/README.md index adfd14d..cd52753 100644 --- a/README.md +++ b/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("

google >

")) #> diff --git a/src/Makevars b/src/Makevars index dffff09..c6616f4 100644 --- a/src/Makevars +++ b/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 diff --git a/src/htmltidy.cpp b/src/htmltidy.cpp index 815e79d..af09e17 100644 --- a/src/htmltidy.cpp +++ b/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(output.bp)); tidyBufFree(&output); diff --git a/tests/testthat/test-htmltidy.R b/tests/testthat/test-htmltidy.R index ab6f62f..1c552c5 100644 --- a/tests/testthat/test-htmltidy.R +++ b/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("

google >

")), + equals(256)) })