Skip to content

Commit

Permalink
Improve conformance notation matching
Browse files Browse the repository at this point in the history
Add test
  • Loading branch information
palemieux committed Dec 22, 2024
1 parent fc85e00 commit 1629690
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 30 deletions.
2 changes: 1 addition & 1 deletion doc/main.html
Original file line number Diff line number Diff line change
Expand Up @@ -492,7 +492,7 @@ <h4>Conformance section</h4>
</pre>
</div>

<p>This section is prohibited when the document is an administrative guideline, operations manual or engineering guideline.</p>
<p>This section is prohibited unless the document is a Standard or Recommended Practice.</p>

</section>

Expand Down
55 changes: 26 additions & 29 deletions smpte.js
Original file line number Diff line number Diff line change
Expand Up @@ -606,14 +606,11 @@ function insertConformance(docMetadata) {

let sec = document.getElementById(SMPTE_CONFORMANCE_ID);

if (docMetadata.pubType == smpte.OM_PUBTYPE) {
if (!(docMetadata.pubType == smpte.RP_PUBTYPE || docMetadata.pubType == smpte.ST_PUBTYPE)) {
if (sec !== null)
logger_.error("OM must not contain a Conformance section.");
return;
}

if ((docMetadata.pubType == smpte.EG_PUBTYPE) && (sec !== null)) {
logger_.error("EG must not contain a Conformance section.");
logger_.error(`An ${docMetadata.pubType} document must not contain a conformance section`);
if (docMetadata.pubType != smpte.EG_PUBTYPE)
return;
}

if (sec === null) {
Expand Down Expand Up @@ -691,28 +688,6 @@ function insertConformance(docMetadata) {

}

if (docMetadata.pubType === smpte.EG_PUBTYPE) {

for (let section of document.querySelectorAll("body > section")) {

let id = section.id;

if (id === "sec-front-matter" || id === "sec-foreword" || id === "sec-conformance")
continue;

if (section.innerText.toLowerCase().includes("shall")) {
logger_.error(`EG must not contain Conformance Notation - "shall" found`, section);
}
if (section.innerText.toLowerCase().includes("should")) {
logger_.error(`EG must not contain Conformance Notation - "should" found`, section);
}
if (section.innerText.toLowerCase().includes("may")) {
logger_.error(`EG must not contain Conformance Notation - "may" found`, section);
}

};
}

}

const SMPTE_FOREWORD_ID = "sec-foreword";
Expand Down Expand Up @@ -1280,6 +1255,27 @@ function resolveLinks(docMetadata) {
}
}

const CONFORMANCE_RE = /\s*(shall)|(should)|(may)\s/i;

function checkConformanceNotation(docMetadata) {
if (docMetadata.pubType !== smpte.EG_PUBTYPE)
return;

for (let section of document.querySelectorAll("section:not(:has(section))")) {

const id = section.id;

if (id === SMPTE_FRONT_MATTER_ID || id === SMPTE_FOREWORD_ID || id === SMPTE_CONFORMANCE_ID)
continue;

const r = CONFORMANCE_RE.exec(section.innerText);

if (r !== null)
logger_.error(`An EG must not contain the conformance notation ${r[1]}`, section);

};
}

function asyncInsertSnippets() {
return Promise.all(Array.from(
document.querySelectorAll("pre[data-include]"),
Expand Down Expand Up @@ -1326,6 +1322,7 @@ async function render() {
let docMetadata = loadDocMetadata();

insertIconLink();
checkConformanceNotation(docMetadata);
insertFrontMatter(docMetadata);
insertForeword(docMetadata);
insertIntroduction(docMetadata);
Expand Down
27 changes: 27 additions & 0 deletions test/resources/html/validation/eg-conformance-valid.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<!doctype html>
<html>
<head itemscope="itemscope" itemtype="http://smpte.org/standards/documents">
<meta charset="utf-8" />
<meta http-equiv="x-ua-compatible" content="ie=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<script type="module" src="../../../../smpte.js"></script>
<meta itemprop="test" content="valid" />
<meta itemprop="pubType" content="EG" />
<meta itemprop="pubNumber" content="429" />
<meta itemprop="pubPart" content="6" />
<meta itemprop="pubSuiteTitle" content="Suite title" />
<meta itemprop="pubTC" content="27C" />
<meta itemprop="pubStage" content="WD" />
<meta itemprop="pubState" content="draft" />
<title>Title of the document</title>
</head>
<body>
<section id="sec-scope">
<p>This is the scope of the document.</p>
</section>
<section id="sec-a">
<h2>A</h2>
<p>The cat is blue.</p>
</section>
</body>
</html>

0 comments on commit 1629690

Please sign in to comment.