@@ -361,17 +361,26 @@ const HTML_WEIGHT_MAP = Dict{Symbol, Int}(
361
361
:extrabold => 800 ,
362
362
:black => 900 )
363
363
364
- function htmlstyle (io:: IO , face:: Face , lastface:: Face = getface ())
365
- print (io, " <span style=\" " )
364
+ function cssattrs (io:: IO , face:: Face , lastface:: Face = getface (), escapequotes:: Bool = true )
365
+ priorattr = false
366
+ function printattr (io, attr, valparts... )
367
+ if priorattr
368
+ print (io, " ; " )
369
+ else
370
+ priorattr = true
371
+ end
372
+ print (io, attr, " : " , valparts... )
373
+ end
366
374
face. font == lastface. font ||
367
- print (io, " font-family: \" " ,
368
- replace (face. font, ' "' => " "" , ' '' => " '" ), ' "' )
375
+ printattr (io, " font-family" , ifelse (escapequotes, " "" , " \" " ),
376
+ replace (face. font, ' "' => " \\ "" , ' '' => " '" ),
377
+ ifelse (escapequotes, " "" , " \" " ))
369
378
face. height == lastface. height ||
370
- print (io, " font-size: " , string (face. height ÷ 10 ), " pt; " )
379
+ printattr (io, " font-size" , string (face. height ÷ 10 ), " pt" )
371
380
face. weight == lastface. weight ||
372
- print (io, " font-weight: " , get (HTML_WEIGHT_MAP, face. weight, 400 ), ' ; ' )
381
+ printattr (io, " font-weight" , get (HTML_WEIGHT_MAP, face. weight, 400 ))
373
382
face. slant == lastface. slant ||
374
- print (io, " font-style: " , String (face. slant), ' ; ' )
383
+ printattr (io, " font-style" , String (face. slant))
375
384
foreground, background =
376
385
ifelse (face. inverse === true ,
377
386
(face. background, face. foreground),
@@ -381,19 +390,17 @@ function htmlstyle(io::IO, face::Face, lastface::Face=getface())
381
390
(lastface. background, lastface. foreground),
382
391
(lastface. foreground, lastface. background))
383
392
if foreground != lastforeground
384
- print (io, " color: " )
393
+ printattr (io, " color" )
385
394
htmlcolor (io, foreground)
386
- print (io, ' ;' )
387
395
end
388
396
if background != lastbackground
389
- print (io, " background-color: " )
397
+ printattr (io, " background-color" )
390
398
htmlcolor (io, background)
391
- print (io, ' ;' )
392
399
end
393
400
face. underline == lastface. underline ||
394
401
if face. underline isa Tuple # Color and style
395
402
color, style = face. underline
396
- print (io, " text-decoration: " )
403
+ printattr (io, " text-decoration" )
397
404
if ! isnothing (color)
398
405
htmlcolor (io, color)
399
406
print (io, ' ' )
@@ -403,17 +410,16 @@ function htmlstyle(io::IO, face::Face, lastface::Face=getface())
403
410
elseif style == :curly " wavy "
404
411
elseif style == :dotted " dotted "
405
412
elseif style == :dashed " dashed "
406
- else " " end )
407
- print (io, " underline;" )
413
+ else " " end , " underline" )
408
414
elseif face. underline isa SimpleColor
409
- print (io, " text-decoration: " )
415
+ printattr (io, " text-decoration" )
410
416
htmlcolor (io, face. underline)
411
417
if lastface. underline isa Tuple && last (lastface. underline) != :straight
412
418
print (io, " solid" )
413
419
end
414
- print (io, " underline; " )
420
+ print (io, " underline" )
415
421
else # must be a Bool
416
- print (io, " text-decoration: " )
422
+ printattr (io, " text-decoration" )
417
423
if lastface. underline isa SimpleColor
418
424
print (io, " currentcolor " )
419
425
elseif lastface. underline isa Tuple
@@ -422,13 +428,16 @@ function htmlstyle(io::IO, face::Face, lastface::Face=getface())
422
428
last (lastface. underline) != :straight &&
423
429
print (io, " straight " )
424
430
end
425
- print (io, ifelse (face. underline, " underline; " , " none; " ))
431
+ print (io, ifelse (face. underline, " underline" , " none" ))
426
432
end
427
433
face. strikethrough == lastface. strikethrough ||
428
- print (io, ifelse (face. strikethrough,
429
- " text-decoration: line-through" ,
430
- ifelse (face. underline === false ,
431
- " text-decoration: none" , " " )))
434
+ ! face. strikethrough && face. underline != = false ||
435
+ printattr (io, " text-decoration" , ifelse (face. strikethrough, " line-through" , " none" ))
436
+ end
437
+
438
+ function htmlstyle (io:: IO , face:: Face , lastface:: Face = getface ())
439
+ print (io, " <span style=\" " )
440
+ cssattrs (io, face, lastface, true )
432
441
print (io, " \" >" )
433
442
end
434
443
0 commit comments