Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Resolve Faces when applying styling #7

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
14 changes: 7 additions & 7 deletions src/JuliaSyntaxHighlighting.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module JuliaSyntaxHighlighting

import Base: JuliaSyntax, AnnotatedString, annotate!
import Base.JuliaSyntax: @K_str, Kind, GreenNode, parseall, kind, flags
using StyledStrings: Face, addface!
using StyledStrings: Face, addface!, getface

public highlight, highlight!

Expand Down 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
Loading