|
5 | 5 |
|
6 | 6 | module StyledMarkup
|
7 | 7 |
|
8 |
| -using Base: AnnotatedString, annotatedstring |
| 8 | +using Base: AnnotatedString, annotations, annotatedstring |
9 | 9 | using ..StyledStrings: Face, SimpleColor
|
10 | 10 |
|
11 | 11 | export @styled_str, styled
|
@@ -97,7 +97,7 @@ function addpart!(state::State, stop::Int)
|
97 | 97 | range = (start - state.point[]):(stop - state.point[] + state.offset[] + 1)
|
98 | 98 | push!(styles, tupl(range, annot))
|
99 | 99 | end
|
100 |
| - sort!(state.pending_styles, by = (r -> (first(r), -last(r))) ∘ first) # see `Base._annot_sortkey` |
| 100 | + sort!(state.pending_styles, by = (r -> (first(r), -last(r))) ∘ first) # Prioritise the most specific styles |
101 | 101 | for (range, annot) in state.pending_styles
|
102 | 102 | if !isempty(range)
|
103 | 103 | push!(styles, tupl(range .- state.point[], annot))
|
@@ -135,11 +135,15 @@ function addpart!(state::State, start::Int, expr, stop::Int)
|
135 | 135 | else
|
136 | 136 | push!(state.parts,
|
137 | 137 | :(let $str = string($expr)
|
138 |
| - if isempty($str) |
139 |
| - "" |
| 138 | + $len = ncodeunits($str) # Used in `annots`. |
| 139 | + if $str isa AnnotatedString && !isempty($str) |
| 140 | + AnnotatedString(String($str), vcat($annots, annotations($str))) |
140 | 141 | else
|
141 |
| - $len = ncodeunits($str) |
142 |
| - AnnotatedString($str, $annots) |
| 142 | + if isempty($str) |
| 143 | + "" |
| 144 | + else |
| 145 | + AnnotatedString($str, $annots) |
| 146 | + end |
143 | 147 | end
|
144 | 148 | end))
|
145 | 149 | end
|
|
0 commit comments