@@ -46,7 +46,7 @@ Of course, as usual, the devil is in the details.
46
46
module StyledMarkup
47
47
48
48
using Base: AnnotatedString, annotations, annotatedstring
49
- using .. StyledStrings: Face, SimpleColor
49
+ using .. StyledStrings: Face, SimpleColor, getface
50
50
51
51
export @styled_str , styled
52
52
@@ -325,7 +325,7 @@ function readexpr!(state::State, pos::Int = first(popfirst!(state.s)) + 1)
325
325
if isempty (state. s)
326
326
styerr! (state,
327
327
AnnotatedString (" Identifier or parenthesised expression expected after \$ in string" ,
328
- [(55 : 55 , :face , :warning )]),
328
+ [(55 : 55 , :face , getface ( :warning ) )]),
329
329
- 1 , " right here" )
330
330
return " " , pos
331
331
end
@@ -401,7 +401,7 @@ and register it in the active styles list.
401
401
"""
402
402
function begin_style! (state:: State , i:: Int , char:: Char )
403
403
hasvalue = false
404
- newstyles = Vector{Tuple{Int, Int, Union{Symbol, Expr, Tuple{Symbol, Any}}}}()
404
+ newstyles = Vector{Tuple{Int, Int, Union{Expr, Tuple{Symbol, Any}}}}()
405
405
while read_annotation! (state, i, char, newstyles) end
406
406
push! (state. active_styles, reverse! (newstyles))
407
407
# Adjust bytes/offset based on how much the index
@@ -535,9 +535,9 @@ function read_inlineface!(state::State, i::Int, char::Char, newstyles)
535
535
valid_options = join (VALID_UNDERLINE_STYLES, " , " , " , or " )
536
536
styerr! (state,
537
537
AnnotatedString (" Invalid underline style '$ustyle_word ' (should be $valid_options )" ,
538
- [(26 : 25 + ncodeunits (ustyle_word), :face , :warning )
538
+ [(26 : 25 + ncodeunits (ustyle_word), :face , getface ( :warning ) )
539
539
(28 + ncodeunits (ustyle_word): 39 + ncodeunits (ustyle_word)+ ncodeunits (valid_options),
540
- :face , :light )]),
540
+ :face , getface ( :light ) )]),
541
541
- length (ustyle_word) - 3 )
542
542
end
543
543
ustyle = Symbol (ustyle_word)
@@ -658,24 +658,24 @@ function read_inlineface!(state::State, i::Int, char::Char, newstyles)
658
658
else
659
659
invalid, lastchar = readsymbol! (state, lastchar)
660
660
styerr! (state, AnnotatedString (" Invalid height '$invalid ', should be a natural number or positive float" ,
661
- [(17 : 16 + ncodeunits (string (invalid)), :face , :warning )]),
661
+ [(17 : 16 + ncodeunits (string (invalid)), :face , getface ( :warning ) )]),
662
662
- 3 )
663
663
end
664
664
elseif key ∈ (:weight , :slant )
665
665
v, lastchar = readalph! (state, lastchar)
666
666
if key == :weight && v ∉ VALID_WEIGHTS
667
667
valid_options = join (VALID_WEIGHTS, " , " , " , or " )
668
668
styerr! (state, AnnotatedString (" Invalid weight '$v ' (should be $valid_options )" ,
669
- [(17 : 16 + ncodeunits (v), :face , :warning ),
669
+ [(17 : 16 + ncodeunits (v), :face , getface ( :warning ) ),
670
670
(19 + ncodeunits (v): 30 + ncodeunits (v)+ ncodeunits (valid_options),
671
- :face , :light )]),
671
+ :face , getface ( :light ) )]),
672
672
- 3 )
673
673
elseif key == :slant && v ∉ VALID_SLANTS
674
674
valid_options = join (VALID_SLANTS, " , " , " , or " )
675
675
styerr! (state, AnnotatedString (" Invalid slant '$v ' (should be $valid_options )" ,
676
- [(16 : 15 + ncodeunits (v), :face , :warning ),
676
+ [(16 : 15 + ncodeunits (v), :face , getface ( :warning ) ),
677
677
(18 + ncodeunits (v): 29 + ncodeunits (v)+ ncodeunits (valid_options),
678
- :face , :light )]),
678
+ :face , getface ( :light ) )]),
679
679
- 3 )
680
680
end
681
681
Symbol (v) |> if ismacro (state) QuoteNode else identity end
@@ -702,7 +702,7 @@ function read_inlineface!(state::State, i::Int, char::Char, newstyles)
702
702
else
703
703
styerr! (state, AnnotatedString (
704
704
" Uses unrecognised face key '$key '. Recognised keys are: $(join (VALID_FACE_ATTRS, " , " , " , and " )) " ,
705
- [(29 : 28 + ncodeunits (String (key)), :face , :warning )]),
705
+ [(29 : 28 + ncodeunits (String (key)), :face , getface ( :warning ) )]),
706
706
- length (str_key) - 2 )
707
707
end
708
708
if ismacro (state) && ! any (k -> first (k. args) == key, kwargs)
@@ -711,7 +711,7 @@ function read_inlineface!(state::State, i::Int, char::Char, newstyles)
711
711
push! (kwargs, key => val)
712
712
else
713
713
styerr! (state, AnnotatedString (" Contains repeated face key '$key '" ,
714
- [(29 : 28 + ncodeunits (String (key)), :face , :warning )]),
714
+ [(29 : 28 + ncodeunits (String (key)), :face , getface ( :warning ) )]),
715
715
- length (str_key) - 2 )
716
716
end
717
717
isempty (state. s) && styerr! (state, " Incomplete inline face declaration" , - 1 )
@@ -727,11 +727,11 @@ function read_inlineface!(state::State, i::Int, char::Char, newstyles)
727
727
push! (newstyles,
728
728
(i, i + state. offset + 1 ,
729
729
if ! ismacro (state)
730
- :face , Face (; NamedTuple (kwargs)... )
730
+ ( :face , Face (; NamedTuple (kwargs)... ) )
731
731
elseif needseval
732
732
:((:face , $ face))
733
733
else
734
- :face , hygienic_eval (state, face)
734
+ ( :face , hygienic_eval (state, face) )
735
735
end ))
736
736
end
737
737
@@ -803,6 +803,7 @@ function read_face_or_keyval!(state::State, i::Int, char::Char, newstyles)
803
803
push! (newstyles,
804
804
(i, i + state. offset + ncodeunits (' {' ),
805
805
if key isa String && ! (value isa Symbol || value isa Expr)
806
+ # TODO
806
807
Symbol (key), value
807
808
elseif key isa Expr || key isa Symbol
808
809
:(($ key, $ value))
@@ -813,9 +814,11 @@ function read_face_or_keyval!(state::State, i::Int, char::Char, newstyles)
813
814
push! (newstyles,
814
815
(i, i + state. offset + ncodeunits (' {' ),
815
816
if key isa Symbol || key isa Expr
816
- :((:face , $ key))
817
+ :((:face , $ getface ($ key)))
818
+ elseif ismacro (state) # Face symbol
819
+ :((:face , $ getface ($ (QuoteNode (Symbol (key))))))
817
820
else # Face symbol
818
- :face , Symbol (key)
821
+ ( :face , getface ( Symbol (key)) )
819
822
end ))
820
823
end
821
824
if isempty (state. s) || last (peek (state. s)) ∉ (' ' , ' \t ' , ' \n ' , ' \r ' , ' ,' , ' :' )
@@ -857,7 +860,7 @@ function run_state_machine!(state::State)
857
860
end
858
861
for incomplete in Iterators. flatten (state. active_styles)
859
862
styerr! (state, AnnotatedString (" Unterminated annotation (missing closing '}')" ,
860
- [(43 : 43 , :face , :warning )]),
863
+ [(43 : 43 , :face , getface ( :warning ) )]),
861
864
prevind (state. content, first (incomplete)), " starts here" )
862
865
end
863
866
end
0 commit comments