mihaiconstantin / powerly

`powerly` is an R package for conducting sample size analysis for network models and more.
https://powerly.dev
Other
7 stars 3 forks source link

CRAN checks produce `HTML` validation errors #30

Closed mihaiconstantin closed 2 years ago

mihaiconstantin commented 2 years ago

Upon submitting to CRAN, the following NOTE was produced:

- checking HTML version of manual ... [0s/1s] NOTE
    Found the following HTML validation problems:
    plot.Method.html:107:1: Warning: inserting implicit <p>
    plot.Method.html:112:1: Warning: inserting implicit <p>
    plot.Method.html:118:1: Warning: inserting implicit <p>
    plot.StepOne.html:86:1: Warning: inserting implicit <p>
    plot.StepThree.html:86:1: Warning: inserting implicit <p>
    plot.StepTwo.html:86:1: Warning: inserting implicit <p>
    plot.Validation.html:92:1: Warning: inserting implicit <p>

The issue seems to be with the \if{html}{...} parts in the documentation.

Take, for example, the following code (i.e., at 7e068a9) in file plot-Validation.R:

https://github.com/mihaiconstantin/powerly/blob/7e068a9ff57cdc532413b78f5fff1bd236404261/man-roxygen/plot-Validation.R#L37-L43

First, regenerate the ./man/plot.Validation.Rd file via, e.g., devtools::document(). Then, parse the .Rd file to HTML via tools::Rd2HTML("./man/plot.Validation.Rd"). The HTML output looks like this (i.e., indentation preserved):

<!-- ... -->

<p>Example of a validation plot:
</p>
<div style="text-align: center">
<p><img src="../help/figures/example-validation.png" style="width: 640px; max-width: 90%;" alt="Example Validation" />
</div>

</p>

<!-- ... -->

Note that the empty line below the #' Example of a validation plot: line confuses the parser, which closes the <p> tag. Also, according to HTML semantics it is not valid to have block-level content between <p>...</p>.

The problem seems to go away by removing the empty line mentioned above, which will result in the following HTML:

<!-- ... -->

<p>Example of a validation plot:
<div style="text-align: center">
<img src="../help/figures/example-validation.png" style="width: 640px; max-width: 90%;" alt="Example Validation" />
</div>

</p>

<!-- ... -->
mihaiconstantin commented 2 years ago

This does not solve the issue. The tidy utility (i.e., html-tidy.org) still produces a warning when ran against the following HTML:

<!DOCTYPE html>
<html lang="en">
<head>
    <title>Test</title>
</head>
<body>
    <p>
        Example of a validation plot:
        <div style="text-align: center">
            <img src="../help/figures/example-validation.png" style="width: 640px; max-width: 90%;" alt="Example Validation" />
        </div>
    </p>
</body>
</html>

Namely:

line 12 column 5 - Warning: inserting implicit <p>

The same can be observed from the online HTML validator at validator.w3.org, which produces:

CleanShot 2022-09-09 at 14 55 34@2x

The issue seems due to placing a div element inside the p element. This is not allowed since it is not semantically correct.

One way around this is to replace:

<p>
    Example of a validation plot:
    <div style="text-align: center">
        <img src="../help/figures/example-validation.png" style="width: 640px; max-width: 90%;" alt="Example Validation" />
    </div>
</p>

with:

<p>
    Example of a validation plot:
    <span style="display: block; text-align: center;">
        <img src="../help/figures/example-validation.png" style="width: 640px; max-width: 90%;" alt="Example Validation" />
    </span>
</p>