@@ -6,9 +6,9 @@ import containerFlow from 'mdast-util-to-markdown/lib/util/container-flow.js'
6
6
import containerPhrasing from 'mdast-util-to-markdown/lib/util/container-phrasing.js'
7
7
import checkQuote from 'mdast-util-to-markdown/lib/util/check-quote.js'
8
8
9
- var own = { } . hasOwnProperty
9
+ const own = { } . hasOwnProperty
10
10
11
- var shortcut = / ^ [ ^ \t \n \r " # ' . < = > ` } ] + $ /
11
+ const shortcut = / ^ [ ^ \t \n \r " # ' . < = > ` } ] + $ /
12
12
13
13
handleDirective . peek = peekDirective
14
14
@@ -129,7 +129,7 @@ function exitAttributeClassValue(token) {
129
129
}
130
130
131
131
function exitAttributeValue ( token ) {
132
- var attributes = this . getData ( 'directiveAttributes' )
132
+ const attributes = this . getData ( 'directiveAttributes' )
133
133
attributes [ attributes . length - 1 ] [ 1 ] = decodeLight ( this . sliceSerialize ( token ) )
134
134
}
135
135
@@ -140,13 +140,12 @@ function exitAttributeName(token) {
140
140
}
141
141
142
142
function exitAttributes ( ) {
143
- var attributes = this . getData ( 'directiveAttributes' )
144
- var cleaned = { }
145
- var index = - 1
146
- var attribute
143
+ const attributes = this . getData ( 'directiveAttributes' )
144
+ const cleaned = { }
145
+ let index = - 1
147
146
148
147
while ( ++ index < attributes . length ) {
149
- attribute = attributes [ index ]
148
+ const attribute = attributes [ index ]
150
149
151
150
if ( attribute [ 0 ] === 'class' && cleaned . class ) {
152
151
cleaned . class += ' ' + attribute [ 1 ]
@@ -165,17 +164,16 @@ function exit(token) {
165
164
}
166
165
167
166
function handleDirective ( node , _ , context ) {
168
- var prefix = fence ( node )
169
- var exit = context . enter ( node . type )
170
- var value =
167
+ const prefix = fence ( node )
168
+ const exit = context . enter ( node . type )
169
+ let value =
171
170
prefix +
172
171
( node . name || '' ) +
173
172
label ( node , context ) +
174
173
attributes ( node , context )
175
- var subvalue
176
174
177
175
if ( node . type === 'containerDirective' ) {
178
- subvalue = content ( node , context )
176
+ const subvalue = content ( node , context )
179
177
if ( subvalue ) value += '\n' + subvalue
180
178
value += '\n' + prefix
181
179
}
@@ -189,58 +187,56 @@ function peekDirective() {
189
187
}
190
188
191
189
function label ( node , context ) {
192
- var label = node
193
- var exit
194
- var subexit
195
- var value
190
+ let label = node
196
191
197
192
if ( node . type === 'containerDirective' ) {
198
193
if ( ! inlineDirectiveLabel ( node ) ) return ''
199
194
label = node . children [ 0 ]
200
195
}
201
196
202
- exit = context . enter ( 'label' )
203
- subexit = context . enter ( node . type + 'Label' )
204
- value = containerPhrasing ( label , context , { before : '[' , after : ']' } )
197
+ const exit = context . enter ( 'label' )
198
+ const subexit = context . enter ( node . type + 'Label' )
199
+ const value = containerPhrasing ( label , context , { before : '[' , after : ']' } )
205
200
subexit ( )
206
201
exit ( )
207
202
return value ? '[' + value + ']' : ''
208
203
}
209
204
210
205
function attributes ( node , context ) {
211
- var quote = checkQuote ( context )
212
- var subset = node . type === 'textDirective' ? [ quote ] : [ quote , '\n' , '\r' ]
213
- var attrs = node . attributes || { }
214
- var values = [ ]
215
- var id
216
- var classesFull
217
- var classes
218
- var value
219
- var key
220
- var index
206
+ const quote = checkQuote ( context )
207
+ const subset = node . type === 'textDirective' ? [ quote ] : [ quote , '\n' , '\r' ]
208
+ const attrs = node . attributes || { }
209
+ const values = [ ]
210
+ let classesFull
211
+ let classes
212
+ let id
213
+ let key
221
214
222
215
for ( key in attrs ) {
223
- if ( own . call ( attrs , key ) && attrs [ key ] != null ) {
224
- value = String ( attrs [ key ] )
216
+ if (
217
+ own . call ( attrs , key ) &&
218
+ attrs [ key ] !== undefined &&
219
+ attrs [ key ] !== null
220
+ ) {
221
+ let value = String ( attrs [ key ] )
225
222
226
223
if ( key === 'id' ) {
227
224
id = shortcut . test ( value ) ? '#' + value : quoted ( 'id' , value )
228
225
} else if ( key === 'class' ) {
229
226
value = value . split ( / [ \t \n \r ] + / g)
230
227
classesFull = [ ]
231
228
classes = [ ]
232
- index = - 1
229
+ let index = - 1
233
230
234
231
while ( ++ index < value . length ) {
235
232
; ( shortcut . test ( value [ index ] ) ? classes : classesFull ) . push (
236
233
value [ index ]
237
234
)
238
235
}
239
236
240
- classesFull = classesFull . length
241
- ? quoted ( 'class' , classesFull . join ( ' ' ) )
242
- : ''
243
- classes = classes . length ? '.' + classes . join ( '.' ) : ''
237
+ classesFull =
238
+ classesFull . length > 0 ? quoted ( 'class' , classesFull . join ( ' ' ) ) : ''
239
+ classes = classes . length > 0 ? '.' + classes . join ( '.' ) : ''
244
240
} else {
245
241
values . push ( quoted ( key , value ) )
246
242
}
@@ -259,7 +255,7 @@ function attributes(node, context) {
259
255
values . unshift ( id )
260
256
}
261
257
262
- return values . length ? '{' + values . join ( ' ' ) + '}' : ''
258
+ return values . length > 0 ? '{' + values . join ( ' ' ) + '}' : ''
263
259
264
260
function quoted ( key , value ) {
265
261
return (
@@ -272,11 +268,12 @@ function attributes(node, context) {
272
268
}
273
269
274
270
function content ( node , context ) {
275
- var content = inlineDirectiveLabel ( node )
276
- ? Object . assign ( { } , node , { children : node . children . slice ( 1 ) } )
277
- : node
278
-
279
- return containerFlow ( content , context )
271
+ return containerFlow (
272
+ inlineDirectiveLabel ( node )
273
+ ? Object . assign ( { } , node , { children : node . children . slice ( 1 ) } )
274
+ : node ,
275
+ context
276
+ )
280
277
}
281
278
282
279
function inlineDirectiveLabel ( node ) {
@@ -300,7 +297,7 @@ function decodeIfPossible($0, $1) {
300
297
}
301
298
302
299
function fence ( node ) {
303
- var size = 0
300
+ let size = 0
304
301
305
302
if ( node . type === 'containerDirective' ) {
306
303
visitParents ( node , 'containerDirective' , onvisit )
@@ -314,8 +311,8 @@ function fence(node) {
314
311
return repeatString ( ':' , size )
315
312
316
313
function onvisit ( node , parents ) {
317
- var index = parents . length
318
- var nesting = 0
314
+ let index = parents . length
315
+ let nesting = 0
319
316
320
317
while ( index -- ) {
321
318
if ( parents [ index ] . type === 'containerDirective' ) {
0 commit comments