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

Privatise the annotations API, for StyledStrings #55453

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
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
7 changes: 0 additions & 7 deletions base/public.jl
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,8 @@ public
ImmutableDict,
OneTo,
LogRange,
AnnotatedString,
AnnotatedChar,
UUID,

# Annotated strings
annotatedstring,
annotate!,
annotations,

# Semaphores
Semaphore,
acquire,
Expand Down
14 changes: 6 additions & 8 deletions base/strings/annotated.jl
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,10 @@ See also [`AnnotatedChar`](@ref), [`annotatedstring`](@ref),
[`annotations`](@ref), and [`annotate!`](@ref).

!!! warning
While the constructors are part of the Base public API, the fields
of `AnnotatedString` are not. This is to allow for potential future
While the constructors are part of the `StyledStrings` public API, the
fields of `AnnotatedString` are not. This is to allow for potential future
changes in the implementation of this type. Instead use the
[`annotations`](@ref), and [`annotate!`](@ref) getter/setter
functions.
[`annotations`](@ref), and [`annotate!`](@ref) getter/setter functions.

# Constructors

Expand Down Expand Up @@ -82,11 +81,10 @@ See also: [`AnnotatedString`](@ref), [`annotatedstring`](@ref), `annotations`,
and `annotate!`.

!!! warning
While the constructors are part of the Base public API, the fields
of `AnnotatedChar` are not. This it to allow for potential future
While the constructors are part of the `StyledStrings` public API, the
fields of `AnnotatedChar` are not. This it to allow for potential future
changes in the implementation of this type. Instead use the
[`annotations`](@ref), and [`annotate!`](@ref) getter/setter
functions.
[`annotations`](@ref), and [`annotate!`](@ref) getter/setter functions.

# Constructors

Expand Down
5 changes: 0 additions & 5 deletions doc/src/base/strings.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,6 @@ Core.String(::AbstractString)
Base.SubString
Base.LazyString
Base.@lazy_str
Base.AnnotatedString
Base.AnnotatedChar
Base.annotatedstring
Base.annotations
Base.annotate!
Base.transcode
Base.unsafe_string
Base.ncodeunits(::AbstractString)
Expand Down
48 changes: 0 additions & 48 deletions doc/src/manual/strings.md
Original file line number Diff line number Diff line change
Expand Up @@ -1203,51 +1203,3 @@ Notice that the first two backslashes appear verbatim in the output, since they
precede a quote character.
However, the next backslash character escapes the backslash that follows it, and the
last backslash escapes a quote, since these backslashes appear before a quote.


## [Annotated Strings](@id man-annotated-strings)

It is sometimes useful to be able to hold metadata relating to regions of a
string. A [`AnnotatedString`](@ref Base.AnnotatedString) wraps another string and
allows for regions of it to be annotated with labelled values (`:label => value`).
All generic string operations are applied to the underlying string. However,
when possible, styling information is preserved. This means you can manipulate a
[`AnnotatedString`](@ref Base.AnnotatedString) —taking substrings, padding them,
concatenating them with other strings— and the metadata annotations will "come
along for the ride".

This string type is fundamental to the [StyledStrings stdlib](@ref
stdlib-styledstrings), which uses `:face`-labelled annotations to hold styling
information.

When concatenating a [`AnnotatedString`](@ref Base.AnnotatedString), take care to use
[`annotatedstring`](@ref Base.annotatedstring) instead of [`string`](@ref) if you want
to keep the string annotations.

```jldoctest
julia> str = Base.AnnotatedString("hello there",
[(1:5, :word => :greeting), (7:11, :label => 1)])
"hello there"

julia> length(str)
11

julia> lpad(str, 14)
" hello there"

julia> typeof(lpad(str, 7))
Base.AnnotatedString{String}

julia> str2 = Base.AnnotatedString(" julia", [(2:6, :face => :magenta)])
" julia"

julia> Base.annotatedstring(str, str2)
"hello there julia"

julia> str * str2 == Base.annotatedstring(str, str2) # *-concatenation still works
true
```

The annotations of a [`AnnotatedString`](@ref Base.AnnotatedString) can be accessed
and modified via the [`annotations`](@ref Base.annotations) and
[`annotate!`](@ref Base.annotate!) functions.