Prospective changes to AnnotatedString and StyledStrings

I may have misunderstood your advice @tecosaur.

In my package extension to XLSX.jl, I’ve written:

setdata!(sheet::Worksheet, ref::CellRef, ss::AnnotatedString{T}) where T = setdata!(sheet, ref, RichTextString(_ssToRuns(ss)))

@static if VERSION >= v"1.14-"
        const _SS_ARG = Union{<:AnnotatedString{>:Face}, SubString{<:AnnotatedString{>:Face}}}
    else
        const _SS_ARG = Union{<:AnnotatedString, SubString{<:AnnotatedString}}
    end

function _ssToRuns(s::_SS_ARG)
    # Do some stuff
end

It works perfectly for pre-1.14.

However, in v1.14, I get

ERROR: MethodError: no method matching _ssToRuns(::AnnotatedString{String})
The function `_ssToRuns` exists, but no method is defined for this combination of argument types.

Closest candidates are:
  _ssToRuns(::Union{AnnotatedString{>:StyledStrings.Face}, SubString{<:AnnotatedString{>:StyledStrings.Face}}})
   @ StyledStringsSstsExt C:\Users\Tim Gebbels\OneDrive\Documents\Julia\XLSX v0.11\XLSX.jl\ext\StyledStringsSstsExt.jl:38

In the REPL, I can do:

julia> using StyledStrings, XLSX

julia> s=styled"{yellow:hello} {blue:there}"
"hello there"

julia> typeof(s)
AnnotatedString{String}

julia> s isa AnnotatedString{>:StyledStrings.Face}
false

I’m generally not very clever at understanding Julia’s type system and I’ve obviously got something wrong here.

Is there anything obvious you can suggest?

I’ve got things working now.

As suggested in the StylesStrings.jl docs, I’ve opened an issue to request making some currently internal functions public.

1 Like