@@ -361,17 +361,26 @@ const HTML_WEIGHT_MAP = Dict{Symbol, Int}(
361361 :extrabold => 800 ,
362362 :black => 900 )
363363
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
366374 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, " "" , " \" " ))
369378 face. height == lastface. height ||
370- print (io, " font-size: " , string (face. height ÷ 10 ), " pt; " )
379+ printattr (io, " font-size" , string (face. height ÷ 10 ), " pt" )
371380 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 ))
373382 face. slant == lastface. slant ||
374- print (io, " font-style: " , String (face. slant), ' ; ' )
383+ printattr (io, " font-style" , String (face. slant))
375384 foreground, background =
376385 ifelse (face. inverse === true ,
377386 (face. background, face. foreground),
@@ -381,19 +390,17 @@ function htmlstyle(io::IO, face::Face, lastface::Face=getface())
381390 (lastface. background, lastface. foreground),
382391 (lastface. foreground, lastface. background))
383392 if foreground != lastforeground
384- print (io, " color: " )
393+ printattr (io, " color" )
385394 htmlcolor (io, foreground)
386- print (io, ' ;' )
387395 end
388396 if background != lastbackground
389- print (io, " background-color: " )
397+ printattr (io, " background-color" )
390398 htmlcolor (io, background)
391- print (io, ' ;' )
392399 end
393400 face. underline == lastface. underline ||
394401 if face. underline isa Tuple # Color and style
395402 color, style = face. underline
396- print (io, " text-decoration: " )
403+ printattr (io, " text-decoration" )
397404 if ! isnothing (color)
398405 htmlcolor (io, color)
399406 print (io, ' ' )
@@ -403,17 +410,16 @@ function htmlstyle(io::IO, face::Face, lastface::Face=getface())
403410 elseif style == :curly " wavy "
404411 elseif style == :dotted " dotted "
405412 elseif style == :dashed " dashed "
406- else " " end )
407- print (io, " underline;" )
413+ else " " end , " underline" )
408414 elseif face. underline isa SimpleColor
409- print (io, " text-decoration: " )
415+ printattr (io, " text-decoration" )
410416 htmlcolor (io, face. underline)
411417 if lastface. underline isa Tuple && last (lastface. underline) != :straight
412418 print (io, " solid" )
413419 end
414- print (io, " underline; " )
420+ print (io, " underline" )
415421 else # must be a Bool
416- print (io, " text-decoration: " )
422+ printattr (io, " text-decoration" )
417423 if lastface. underline isa SimpleColor
418424 print (io, " currentcolor " )
419425 elseif lastface. underline isa Tuple
@@ -422,13 +428,16 @@ function htmlstyle(io::IO, face::Face, lastface::Face=getface())
422428 last (lastface. underline) != :straight &&
423429 print (io, " straight " )
424430 end
425- print (io, ifelse (face. underline, " underline; " , " none; " ))
431+ print (io, ifelse (face. underline, " underline" , " none" ))
426432 end
427433 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 )
432441 print (io, " \" >" )
433442end
434443
0 commit comments