Skip to content

Commit

Permalink
Resolve Faces when applying styling
Browse files Browse the repository at this point in the history
This is the JuliaSyntaxHighlighting counterpart to:
JuliaLang/StyledStrings.jl#99
  • Loading branch information
topolarity committed Oct 16, 2024
1 parent 19bd57b commit b3da1ba
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions src/JuliaSyntaxHighlighting.jl
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ function _hl_annotations!(highlights::Vector{@NamedTuple{region::UnitRange{Int},
elseif nkind == K"`" || nkind == K"```"; :julia_cmdstring
elseif nkind == K"Char"
kind(lnode) == K"'" && !isempty(highlights) &&
(highlights[end] = (highlights[end][1], :face, :julia_char_delim))
(highlights[end] = (highlights[end][1], :face, getface(:julia_char_delim)))
:julia_char
elseif nkind == K"'" && kind(lnode) == K"Char"; :julia_char_delim
elseif nkind == K"true" || nkind == K"false"; :julia_bool
Expand All @@ -247,8 +247,8 @@ function _hl_annotations!(highlights::Vector{@NamedTuple{region::UnitRange{Int},
if nkind == K"="
ifelse(ppkind == K"for", :julia_keyword, :julia_assignment)
else # updating for <op>=
push!(highlights, (firstindex(content)+offset:node.span+offset-1, :face, :julia_operator))
push!(highlights, (node.span+offset:node.span+offset, :face, :julia_assignment))
push!(highlights, (firstindex(content)+offset:node.span+offset-1, :face, getface(:julia_operator)))
push!(highlights, (node.span+offset:node.span+offset, :face, getface(:julia_assignment)))
nothing
end
elseif nkind == K";" && pkind == K"parameters" && pnode == lnode
Expand Down Expand Up @@ -321,19 +321,19 @@ function _hl_annotations!(highlights::Vector{@NamedTuple{region::UnitRange{Int},
end
end
!isnothing(face) &&
push!(highlights, (region, :face, face))
push!(highlights, (region, :face, getface(face)))
if nkind == K"Comment"
for match in eachmatch(
r"(?:^|[(\[{[:space:]-])`([^[:space:]](?:.*?[^[:space:]])?)`(?:$|[!,\-.:;?\[\][:space:]])",
regionstr)
code = first(match.captures)
push!(highlights, (firstindex(content)+offset+code.offset:firstindex(content)+offset+code.offset+code.ncodeunits-1,
:face, :code))
:face, getface(:code)))
end
elseif nkind == K"String"
for match in eachmatch(r"\\.", regionstr)
push!(highlights, (firstindex(content)+offset+match.offset-1:firstindex(content)+offset+match.offset+ncodeunits(match.match)-2,
:face, :julia_backslash_literal))
:face, getface(:julia_backslash_literal)))
end
end
isempty(node.args) && return
Expand Down

0 comments on commit b3da1ba

Please sign in to comment.