@@ -43,9 +43,9 @@ function restrictReferences(utils, content) {
43
43
// class 'termlist', and if the target of that reference is
44
44
// also within a 'dl' element of class 'termlist', then
45
45
// consider it an internal reference and ignore it.
46
- require ( [ "core/pubsubhub" ] , function ( respecEvents ) {
46
+ require ( [ "core/pubsubhub" ] , ( respecEvents ) => {
47
47
"use strict" ;
48
- respecEvents . sub ( 'end' , function ( message ) {
48
+ respecEvents . sub ( 'end' , ( message ) => {
49
49
if ( message === 'core/link-to-dfn' ) {
50
50
// all definitions are linked; find any internal references
51
51
const internalTerms = document . querySelectorAll ( ".termlist a.internalDFN" ) ;
@@ -69,7 +69,7 @@ require(["core/pubsubhub"], function(respecEvents) {
69
69
70
70
// clearRefs is recursive. Walk down the tree of
71
71
// references to ensure that all references are resolved.
72
- const clearRefs = function ( theTerm ) {
72
+ const clearRefs = ( theTerm ) => {
73
73
if ( termsReferencedByTerms [ theTerm ] ) {
74
74
for ( const item of termsReferencedByTerms [ theTerm ] ) {
75
75
if ( termNames [ item ] ) {
@@ -142,10 +142,10 @@ require(["core/pubsubhub"], function(respecEvents) {
142
142
* use include the github.io address (as it should...)
143
143
*
144
144
*/
145
- require ( [ "core/pubsubhub" ] , function ( respecEvents ) {
145
+ require ( [ "core/pubsubhub" ] , ( respecEvents ) => {
146
146
"use strict" ;
147
- respecEvents . sub ( 'beforesave' , function ( documentElement ) {
148
- $ ( "a[href]" , documentElement ) . each ( function ( index ) {
147
+ respecEvents . sub ( 'beforesave' , ( documentElement ) => {
148
+ $ ( "a[href]" , documentElement ) . each ( ( index ) => {
149
149
// Don't rewrite these.
150
150
if ( $ ( this , documentElement ) . closest ( 'dd' ) . prev ( ) . text ( ) . match ( / L a t e s t e d i t o r | T e s t s u i t e | I m p l e m e n t a t i o n r e p o r t / ) ) return ;
151
151
if ( $ ( this , documentElement ) . closest ( 'section.preserve' ) . length > 0 ) return ;
@@ -165,23 +165,55 @@ require(["core/pubsubhub"], function(respecEvents) {
165
165
} ) ;
166
166
} ) ;
167
167
168
+ /*
169
+ * Implement tabbed examples.
170
+ */
171
+ require ( [ "core/pubsubhub" ] , ( respecEvents ) => {
172
+ "use strict" ;
173
+ respecEvents . sub ( 'end-all' , ( documentElement ) => {
174
+ for ( const button of document . querySelectorAll ( ".ds-selector-tabs .selectors button" ) ) {
175
+ button . onclick = ( ) => {
176
+ const ex = button . closest ( ".ds-selector-tabs" ) ;
177
+ ex . querySelector ( "button.selected" ) . classList . remove ( "selected" ) ;
178
+ ex . querySelector ( ".selected" ) . classList . remove ( "selected" ) ;
179
+ button . classList . add ( 'selected' ) ;
180
+ ex . querySelector ( "." + button . dataset . selects ) . classList . add ( "selected" ) ;
181
+ }
182
+ }
183
+ } ) ;
184
+ } ) ;
185
+
168
186
function _esc ( s ) {
169
187
return s . replace ( / & / g, '&' )
170
188
. replace ( / > / g, '>' )
171
189
. replace ( / " / g, '"' )
172
190
. replace ( / < / g, '<' ) ;
173
191
}
174
192
193
+ function reindent ( text ) {
194
+ // TODO: use trimEnd when Edge supports it
195
+ const lines = text . trimRight ( ) . split ( "\n" ) ;
196
+ while ( lines . length && ! lines [ 0 ] . trim ( ) ) {
197
+ lines . shift ( ) ;
198
+ }
199
+ const indents = lines . filter ( s => s . trim ( ) ) . map ( s => s . search ( / [ ^ \s ] / ) ) ;
200
+ const leastIndent = Math . min ( ...indents ) ;
201
+ return lines . map ( s => s . slice ( leastIndent ) ) . join ( "\n" ) ;
202
+ }
203
+
175
204
function updateExample ( doc , content ) {
176
205
// perform transformations to make it render and prettier
177
- return _esc ( unComment ( doc , content ) )
206
+ return _esc ( reindent ( unComment ( doc , content ) ) )
178
207
. replace ( / \* \* \* \* ( [ ^ * ] * ) \* \* \* \* / g, '<span class="hl-bold">$1</span>' )
179
208
. replace ( / # # # # ( [ ^ # ] * ) # # # # / g, '<span class="comment">$1</span>' ) ;
180
209
}
181
210
182
211
183
212
function unComment ( doc , content ) {
184
213
// perform transformations to make it render and prettier
185
- return content . replace ( / < ! - - / , '' )
186
- . replace ( / - - > / , '' ) ;
214
+ return content
215
+ . replace ( / < ! - - / , '' )
216
+ . replace ( / - - > / , '' )
217
+ . replace ( / < ! - - / g, '<!--' )
218
+ . replace ( / - - > / g, '-->' ) ;
187
219
}
0 commit comments