From 914e482b28f2a7a3175758ce36f42bea6afd5f2d Mon Sep 17 00:00:00 2001 From: Jakob Nybo Nissen Date: Fri, 26 Sep 2025 13:13:45 +0200 Subject: [PATCH] Switch noshift substring constructor to new unannotate function --- src/JuliaSyntaxHighlighting.jl | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/JuliaSyntaxHighlighting.jl b/src/JuliaSyntaxHighlighting.jl index 5b63feb..96e4072 100644 --- a/src/JuliaSyntaxHighlighting.jl +++ b/src/JuliaSyntaxHighlighting.jl @@ -460,8 +460,19 @@ function highlight!(str::AnnotatedString; syntax_errors::Bool = false) str end +@static if isdefined(Base, :unannotate) + # This function uses SubString and AnnotatedString internals, but for current + # and future versions, Base.unannotate is defined, and so this cannot break + # in the future. + const unannotate = Base.unannotate +else + function unannotate(s::SubString{AnnotatedString{S}}) where S + SubString{S}(s.string.string, s.offset, s.ncodeunits, Val(:noshift)) + end +end + function highlight!(str::SubString{AnnotatedString{S}}; syntax_errors::Bool = false) where {S} - plainstr = SubString{S}(str.string.string, str.offset, str.ncodeunits, Val(:noshift)) + plainstr = unannotate(str) for ann in _hl_annotations(plainstr, parseall(GreenNode, plainstr, ignore_errors=true); syntax_errors) annotate!(str, ann.region, ann.label, ann.value) end