5
5
//
6
6
// Add class "preserve" to a definition to ensure it is not removed.
7
7
//
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".
11
9
const termNames = [ ] ;
12
- const termLists = [ ] ;
13
10
const termsReferencedByTerms = [ ] ;
14
11
15
12
function restrictReferences ( utils , content ) {
@@ -33,7 +30,6 @@ function restrictReferences(utils, content) {
33
30
34
31
const $container = $ ( ".termlist" , base ) ;
35
32
const containerID = $container . makeID ( "" , "terms" ) ;
36
- termLists . push ( containerID ) ;
37
33
return ( base . innerHTML ) ;
38
34
}
39
35
@@ -87,9 +83,9 @@ require(["core/pubsubhub"], (respecEvents) => {
87
83
// now termsReferencedByTerms has ALL terms that
88
84
// reference other terms, and a list of the
89
85
// terms that they reference
90
- const internalRefs = document . querySelectorAll ( "a.internalDFN " ) ;
86
+ const internalRefs = document . querySelectorAll ( "a[data-link-type='dfn'] " ) ;
91
87
for ( const item of internalRefs ) {
92
- const idref = item . getAttribute ( 'href' ) . replace ( / ^ # / , "" ) ;
88
+ const idref = item . getAttribute ( 'href' ) . replace ( / ^ . * # / , "" ) ;
93
89
// if the item is outside the term list
94
90
if ( ! item . closest ( 'dl.termlist' ) ) {
95
91
clearRefs ( idref ) ;
@@ -99,14 +95,25 @@ require(["core/pubsubhub"], (respecEvents) => {
99
95
// delete any terms that were not referenced.
100
96
for ( const term in termNames ) {
101
97
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 ] ;
110
117
}
111
118
}
112
119
}
0 commit comments