Skip to content

Commit 4bfadfc

Browse files
committed
Update restrictReferences logic for removing unused definitions.
Remove unused definitions not defined in this spec.
1 parent fc59721 commit 4bfadfc

File tree

2 files changed

+27
-19
lines changed

2 files changed

+27
-19
lines changed

common/common.js

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,8 @@
55
//
66
// Add class "preserve" to a definition to ensure it is not removed.
77
//
8-
// the termlist is in a block of class "termlist", so make sure that
9-
// has an ID and put that ID into the termLists array so we can
10-
// interrogate all of the included termlists later.
8+
// the termlist is in a block of class "termlist".
119
const termNames = [] ;
12-
const termLists = [] ;
1310
const termsReferencedByTerms = [] ;
1411

1512
function restrictReferences(utils, content) {
@@ -33,7 +30,6 @@ function restrictReferences(utils, content) {
3330

3431
const $container = $(".termlist", base) ;
3532
const containerID = $container.makeID("", "terms") ;
36-
termLists.push(containerID) ;
3733
return (base.innerHTML);
3834
}
3935

@@ -87,9 +83,9 @@ require(["core/pubsubhub"], (respecEvents) => {
8783
// now termsReferencedByTerms has ALL terms that
8884
// reference other terms, and a list of the
8985
// terms that they reference
90-
const internalRefs = document.querySelectorAll("a.internalDFN");
86+
const internalRefs = document.querySelectorAll("a[data-link-type='dfn']");
9187
for (const item of internalRefs) {
92-
const idref = item.getAttribute('href').replace(/^#/,"") ;
88+
const idref = item.getAttribute('href').replace(/^.*#/,"") ;
9389
// if the item is outside the term list
9490
if (!item.closest('dl.termlist')) {
9591
clearRefs(idref);
@@ -99,14 +95,25 @@ require(["core/pubsubhub"], (respecEvents) => {
9995
// delete any terms that were not referenced.
10096
for (const term in termNames) {
10197
const $p = $("#"+term);
102-
if ($p.length > 0) {
103-
const tList = $p.getDfnTitles();
104-
$p.parent().next().remove(); // remove dd
105-
$p.remove(); // remove dt
106-
for (const item of tList) {
107-
if (respecConfig.definitionMap[item]) {
108-
delete respecConfig.definitionMap[item];
109-
}
98+
// Remove term definitions inside a dt, where data-cite does not start with shortname
99+
if ($p === undefined) { continue; }
100+
if (!$p.parent().is("dt")) { continue; }
101+
if (($p.data("cite") || "").toLowerCase().startsWith(respecConfig.shortName)) { continue; }
102+
103+
const $dt = $p.parent();
104+
const $dd = $dt.next();
105+
106+
// If the associated dd contains a dfn which is _not_ in termNames, warn
107+
if ($dd.children("dfn").length > 0) {
108+
console.log(term + " definition contains definitions " + $dd.children("dfn").attr("id"))
109+
}
110+
console.log("drop term " + term);
111+
const tList = $p.getDfnTitles();
112+
$dd.remove(); // remove dd
113+
$dt.remove(); // remove dt
114+
for (const item of tList) {
115+
if (respecConfig.definitionMap[item]) {
116+
delete respecConfig.definitionMap[item];
110117
}
111118
}
112119
}

index.html

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -377,16 +377,17 @@ <h2>Terminology</h2>
377377
<p>This document uses the following terms as defined in external specifications
378378
and defines terms specific to JSON-LD.</p>
379379

380-
<!-- FIXME: restrictReferences stopped working properly, so removing for now. -->
381-
<div data-include="common/terms.html"></div>
380+
<div data-include="common/terms.html"
381+
data-oninclude="restrictReferences">
382+
</div>
382383

383384
<section>
384385
<h4>Algorithm Terms</h4>
385386

386387
<p>The Following terms are used within specific algorithms.</p>
387388

388-
<div data-include="common/algorithm-terms.html">
389-
</div>
389+
<div data-include="common/algorithm-terms.html"
390+
data-oninclude="restrictReferences">
390391
</section>
391392

392393
</section>

0 commit comments

Comments
 (0)