ProtoRune. RichText
(proto_rune v0.3.0)
Copy Markdown
Builder for AT Protocol rich text with facets.
Handles byte offset calculation and facet generation for mentions, links, and hashtags.
Examples
# Build rich text with mentions and links
{:ok, rt} =
RichText.new()
|> RichText.text("Hello ")
|> RichText.mention("alice.bsky.social")
|> RichText.text("! Check out ")
|> RichText.link("this project", "https://example.com")
|> RichText.text(" ")
|> RichText.hashtag("elixir")
|> RichText.build()
# Use in post
{:ok, post} = ProtoRune.Bsky.post(session, rt)
# Get plain text
plain = RichText.to_plain_text(rt)
# => "Hello @alice.bsky.social! Check out this project #elixir"
Summary
Functions
Builds the rich text, returning a map suitable for use in posts.
Gets the facets from rich text.
Appends a hashtag to the builder.
Appends a link to the builder.
Appends a mention to the builder.
Creates a new rich text builder.
Appends plain text to the builder.
Converts rich text back to plain text.
Types
Functions
Builds the rich text, returning a map suitable for use in posts.
Examples
{:ok, post_data} =
RichText.new()
|> RichText.text("Hello ")
|> RichText.mention("alice.bsky.social")
|> RichText.build()
# Use with Bsky.post
{:ok, post} = ProtoRune.Bsky.post(session, post_data)
Gets the facets from rich text.
Examples
facets = RichText.facets(rt)
Appends a hashtag to the builder.
The hashtag will be formatted as #tag in the text, and a facet will be created.
Examples
rt = RichText.new() |> RichText.hashtag("elixir")
# => "#elixir" in text with tag facet
Appends a link to the builder.
The link text will appear in the final text, and a facet will be created pointing to the URL.
Examples
rt = RichText.new() |> RichText.link("click here", "https://example.com")
Appends a mention to the builder.
The mention will be formatted as @handle in the text. If DID resolution
succeeds, a mention facet will be created. If resolution fails, the text
is added without a facet (plain text mention).
Examples
rt = RichText.new() |> RichText.mention("alice.bsky.social")
# => "@alice.bsky.social" in text with mention facet (if DID resolves)
@spec new() :: t()
Creates a new rich text builder.
Examples
rt = RichText.new()
Appends plain text to the builder.
Examples
rt = RichText.new() |> RichText.text("Hello world")
Converts rich text back to plain text.
Examples
plain = RichText.to_plain_text(rt)