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".
119const termNames = [ ] ;
12- const termLists = [ ] ;
1310const termsReferencedByTerms = [ ] ;
1411
1512function 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
@@ -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 }
0 commit comments