Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 10 additions & 8 deletions src/styledmarkup.jl
Original file line number Diff line number Diff line change
Expand Up @@ -207,20 +207,22 @@ function addpart!(state::State, stop::Int)
str
else
styles = sty_type[]
# Turn active styles into pending styles
relevant_styles = Iterators.filter(
(_, start, _)::Tuple -> start <= stop + state.offset + 1,
Iterators.flatten(state.active_styles))
for (_, start, annot) in relevant_styles
pushfirst!(state.pending_styles, (start:stop+state.offset+1, annot))
end
# Order the pending styles by specificity
sort!(state.pending_styles, by = (r -> (first(r), -last(r))) ∘ first) # Prioritise the most specific styles
for (range, annot) in state.pending_styles
if !isempty(range)
push!(styles, tupl(range .- state.point, annot))
adjrange = (first(range) - state.point):(last(range) - state.point)
push!(styles, tupl(adjrange, annot))
end
end
empty!(state.pending_styles)
relevant_styles = Iterators.filter(
(_, start, _)::Tuple -> start <= stop + state.offset + 1,
Iterators.flatten(map(reverse, state.active_styles)))
for (_, start, annot) in relevant_styles
range = (start - state.point):(stop - state.point + state.offset + 1)
push!(styles, tupl(range, annot))
end
if isempty(styles)
str
elseif !ismacro(state)
Expand Down
5 changes: 5 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,11 @@ end
"val", [$merge((; region=$(1:3)), $NamedTupleLV((:face, $(Face)(foreground = color))))]))) ==
@macroexpand styled"{(foreground=$color):val}"
end
# Partial annotation termination with interpolation
@test styled"{green:a}{red:{blue:b}$('c')}" ==
AnnotatedString{String}("abc", [(1:1, :face, :green),
(2:3, :face, :red),
(2:2, :face, :blue)])

# Trailing (and non-trailing) Backslashes
@test String(styled"\\") == "\\"
Expand Down
Loading