diff --git a/.github/workflows/R-CMD-check.yaml b/.github/workflows/R-CMD-check.yaml
index 0d4c965db..330a4e9d9 100644
--- a/.github/workflows/R-CMD-check.yaml
+++ b/.github/workflows/R-CMD-check.yaml
@@ -66,6 +66,13 @@ jobs:
actions: read
steps:
+ - name: Start HTML validation server
+ run: |
+ docker run --rm -p 8888:8888 -d ghcr.io/validator/validator:latest &&
+ echo "W3C_MARKUP_VALIDATOR_BASEURL=http://0.0.0.0:8888" >> "$GITHUB_ENV"
+ if: runner.os == 'Linux'
+ shell: bash
+
- uses: actions/checkout@v4
- uses: r-lib/actions/setup-r@v2
diff --git a/DESCRIPTION b/DESCRIPTION
index fa3537624..325621513 100644
--- a/DESCRIPTION
+++ b/DESCRIPTION
@@ -73,6 +73,7 @@ Suggests:
downlit (>= 0.4.0),
htmlwidgets,
jsonlite,
+ curl,
rstudioapi,
miniUI,
rsconnect (>= 0.4.3),
diff --git a/R/html.R b/R/html.R
index dad883f82..6959364cd 100644
--- a/R/html.R
+++ b/R/html.R
@@ -279,7 +279,7 @@ split_chapters = function(
# Need to take care of the div tags here before restore_part_html and
# restore_appendix_html erase the section ids of the hidden PART or APPENDIX
# sections.
- if (split_level > 1) {
+ if (FALSE) {
body = x[(i5 + 1):(i6 - 1)]
h1 = grep('^
0)
+ stop(nrow(html_issues),
+ " HTML issues detected:\n ",
+ paste(html_issues$file, html_issues$messages, sep = ': ', collapse = '\n '))
# split by section works correctly
## id is used for html file name
- sections_files = c("section-1.html", "subsection-1.html", "section-2.html", "sub2.html")
+ sections_files = c(
+ "section-1.html", "subsection-1.html",
+ "section-2.html", "sub2.html", "subsection-22.html",
+ "section-3.html", "subsection-3.html"
+ )
+
if (any(!file.exists(file.path("rmd", sections_files))))
stop("Failed to generate sections files")
## reference is working correctly (see #787)
diff --git a/tests/testthat/helper-validate_html.R b/tests/testthat/helper-validate_html.R
new file mode 100644
index 000000000..9e5448169
--- /dev/null
+++ b/tests/testthat/helper-validate_html.R
@@ -0,0 +1,39 @@
+validate_html <- function(
+ files,
+ # using same env variable old package to keep some compatibility
+ base_url = Sys.getenv('W3C_MARKUP_VALIDATOR_BASEURL')
+) {
+ if(base_url == '' || length(files) == 0) return(NULL)
+ lapply(files, function(file) {
+ h <- curl::new_handle()
+ curl::handle_setform(handle = h, out = 'json', file = curl::form_file(file, "text/html"))
+ jsonlite::fromJSON(rawToChar(
+ curl::curl_fetch_memory(base_url, h)$content
+ ))
+ })
+}
+
+simplify_html_validation <- function(results) {
+ if(is.null(results) || length(results) == 0) return(
+ data.frame(file=character(0), messages=character(0))
+ )
+ expected_errors <- c(
+ "Attribute “number” not allowed on element “div” at this point.",
+ "CSS: “border-top”: “solid\\9” is not a “color” value.",
+ "CSS: “border-bottom”: “solid\\9” is not a “color” value."
+
+ )
+ do.call(rbind, lapply(results,
+ function(result) {
+ if(is.null(result)) return(
+ data.frame(file=character(0), messages=character(0))
+ )
+ messages <- result$messages$message[result$messages$type == 'error']
+ messages <- messages[!messages %in% expected_errors]
+ data.frame(
+ file = if (length(messages) > 0) result$url else character(0),
+ messages = messages
+ )
+ }
+ ))
+}
\ No newline at end of file