Skip to content
15 changes: 13 additions & 2 deletions src/w3c/conformance.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,20 @@ function processConformance(conformance, conf) {
* @param {Conf} conf
*/
export function run(conf) {
/** @type {HTMLElement | null} */
const conformance = document.querySelector("section#conformance");
if (conformance && !conformance.classList.contains("override")) {
processConformance(conformance, conf);
if (conformance) {
if (conformance.classList.contains("informative")) {
conformance.classList.remove("informative");
const msg =
"Conformance sections are normative by definition. The `informative` class has been removed.";
const hint =
'Remove `class="informative"` from `<section id="conformance">` to avoid this warning.';
showWarning(msg, name, { hint, elements: [conformance] });
Comment thread
marcoscaceres marked this conversation as resolved.
}
Comment thread
marcoscaceres marked this conversation as resolved.
Comment thread
marcoscaceres marked this conversation as resolved.
if (!conformance.classList.contains("override")) {
processConformance(conformance, conf);
}
}
// Warn when there are RFC2119/RFC8174 keywords, but not conformance section
if (!conformance && Object.keys(rfc2119Usage).length) {
Expand Down
26 changes: 26 additions & 0 deletions tests/spec/w3c/conformance-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,32 @@ describe("W3C — Conformance", () => {
expect(doc.querySelectorAll("#conformance .rfc2119")).toHaveSize(0);
});

it("removes `informative` class and warns when conformance section is marked informative", async () => {
const body = `
<section id="conformance" class="informative">
<p>CONFORMANCE</p>
</section>
<section>
<h2>my section</h2>
<p>MUST be tested.</p>
</section>
`;
const doc = await makeRSDoc(makeStandardOps({}, body));
const conformance = doc.getElementById("conformance");
// The informative class should have been removed
expect(conformance.classList.contains("informative")).toBeFalse();
// A warning should be emitted, not an error
const warnings = doc.respec.warnings.filter(
w => w.plugin === "w3c/conformance"
);
expect(warnings).toHaveSize(1);
expect(warnings[0].message).toContain("normative");
expect(warnings[0].hint).toContain("informative");
expect(
doc.respec.errors.filter(e => e.plugin === "w3c/conformance")
).toHaveSize(0);
Comment thread
marcoscaceres marked this conversation as resolved.
});

it("allows conformance section to be completely overridden via .override css class", async () => {
const body = `
<section>
Expand Down
Loading