Add AnnotatedString display interface (eliminate StyledStrings type-piracy)#56194
Draft
topolarity wants to merge 1 commit intoJuliaLang:masterfrom
Draft
Add AnnotatedString display interface (eliminate StyledStrings type-piracy)#56194topolarity wants to merge 1 commit intoJuliaLang:masterfrom
topolarity wants to merge 1 commit intoJuliaLang:masterfrom
Conversation
d485bb7 to
ccd6ea1
Compare
topolarity
added a commit
that referenced
this pull request
Mar 29, 2025
Excising part of #56194 on the way to reviving that PR.
This is required for downstream libraries (esp. StyledStrings) to be able to influence the display of an AnnotatedString without type-piracy. The idea here is to provide an `iterate`-like display protocol that passes style information into the implementing library, which takes that information (and a "state" from the last display update), and decides how it needs to update the output to render the string. Since AnnotatedStrings don't have a distinguished "owner" or "type" (only their annotations have types), this leads to corner cases where the "laststate" you receive might be from another library. In that case, it's the responsibility of the downstream renderer to discard the laststate information and "reset" the display state as needed.
ccd6ea1 to
5615845
Compare
vtjnash
reviewed
Apr 4, 2025
| end | ||
|
|
||
| function show(io::IO, ::MIME"text/html", s::Union{<:AnnotatedString, SubString{<:AnnotatedString}}) | ||
| htmlescape(str) = replace(str, '&' => "&", '<' => "<", '>' => ">") |
Member
There was a problem hiding this comment.
This seems incomplete, since the commonly given list is &, <, ', ", \0 https://cheatsheetseries.owasp.org/cheatsheets/Cross_Site_Scripting_Prevention_Cheat_Sheet.html#output-encoding-rules-summary
topolarity
added a commit
that referenced
this pull request
Apr 22, 2025
After discussion with Cody, this is an attempt at a more minimal version of #56194. The intent is to work around the invalidation issue introduced by the split design with AnnotatedStrings, resolving the headache for 1.12. Paired with JuliaLang/StyledStrings.jl#115 Many thanks to @topolarity for working out this approach, the discussion on balancing the short/long term fixes for this issue. ------ From my understanding of the problem, this should fix the `write`/`print`/`show` invalidations, but this needs to be checked. --------- Co-authored-by: Cody Tapscott <topolarity@tapscott.me>
KristofferC
pushed a commit
that referenced
this pull request
Apr 24, 2025
After discussion with Cody, this is an attempt at a more minimal version of #56194. The intent is to work around the invalidation issue introduced by the split design with AnnotatedStrings, resolving the headache for 1.12. Paired with JuliaLang/StyledStrings.jl#115 Many thanks to @topolarity for working out this approach, the discussion on balancing the short/long term fixes for this issue. ------ From my understanding of the problem, this should fix the `write`/`print`/`show` invalidations, but this needs to be checked. --------- Co-authored-by: Cody Tapscott <topolarity@tapscott.me> (cherry picked from commit 6d78a4a)
LebedevRI
pushed a commit
to LebedevRI/julia
that referenced
this pull request
May 2, 2025
After discussion with Cody, this is an attempt at a more minimal version of JuliaLang#56194. The intent is to work around the invalidation issue introduced by the split design with AnnotatedStrings, resolving the headache for 1.12. Paired with JuliaLang/StyledStrings.jl#115 Many thanks to @topolarity for working out this approach, the discussion on balancing the short/long term fixes for this issue. ------ From my understanding of the problem, this should fix the `write`/`print`/`show` invalidations, but this needs to be checked. --------- Co-authored-by: Cody Tapscott <topolarity@tapscott.me>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This implements a "rendering interface" for AnnotatedString, allowing StyledStrings to influence printing without type-piracy.
The idea here is to provide an
iterate-like display protocol that passes style information into the implementing library, which takes that information (and a "state" from the last display update), and decides how it needs to update the output to render the string.Since AnnotatedStrings don't have a distinguished "owner" or "type" (only their annotations have types), this means we have to handle cases where the "laststate" you receive might be from another library. In that case, it's the responsibility of the downstream renderer to discard the laststate information and "reset" the display state as needed.
Dependent on #56192, and see JuliaLang/StyledStrings.jl#100 for the StyledStrings-side changes.
This should eliminate 100% of the StyledStrings type-piracy, once implemented.