Skip to content

Commit 914e482

Browse files
committed
Switch noshift substring constructor to new unannotate function
1 parent c642041 commit 914e482

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

src/JuliaSyntaxHighlighting.jl

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -460,8 +460,19 @@ function highlight!(str::AnnotatedString; syntax_errors::Bool = false)
460460
str
461461
end
462462

463+
@static if isdefined(Base, :unannotate)
464+
# This function uses SubString and AnnotatedString internals, but for current
465+
# and future versions, Base.unannotate is defined, and so this cannot break
466+
# in the future.
467+
const unannotate = Base.unannotate
468+
else
469+
function unannotate(s::SubString{AnnotatedString{S}}) where S
470+
SubString{S}(s.string.string, s.offset, s.ncodeunits, Val(:noshift))
471+
end
472+
end
473+
463474
function highlight!(str::SubString{AnnotatedString{S}}; syntax_errors::Bool = false) where {S}
464-
plainstr = SubString{S}(str.string.string, str.offset, str.ncodeunits, Val(:noshift))
475+
plainstr = unannotate(str)
465476
for ann in _hl_annotations(plainstr, parseall(GreenNode, plainstr, ignore_errors=true); syntax_errors)
466477
annotate!(str, ann.region, ann.label, ann.value)
467478
end

0 commit comments

Comments
 (0)