Expand description
Utilities for working with markup.
The purpose of this module is to make it easy and painless to work with
different markups correctly. This module contains abstract formatters like
bold
, italic
, link
, etc. You can pass strings, other formatters,
tuples, slices/arrays and vectors of strings and formatters to them:
use tbot::markup::{italic, bold};
let message = bold((
"*This is <b>old, ",
italic("and this is bold and italic!"),
));
However, you can’t use their return values directly — indeed, how do they
know if they need to format their inputs as HTML or MarkdownV2? That’s where
markup formatters html
and markdown_v2
come into play. They take
the return values from the abstract utilities and return values that can
finally be turned into Text
instances:
use tbot::{markup::markdown_v2, types::parameters::Text};
assert_eq!(
Text::from(markdown_v2(message)),
Text::with_markdown_v2(
// the extra `\r`s are needed for correct parsing in edge cases
"*\\*This is <b\\>old, \r_and this is bold and italic\\!\r_*",
),
);
As you can see, you can fearlessly pass any strings to formatters and they’ll be automatically properly escaped. Magic!
Note that methods that support sending markup take impl Into<
Text
>
,
so you don’t need to turn formatters into Text
manually:
use tbot::{Bot, markup::html, types::chat};
let bot = Bot::from_env("BOT_TOKEN");
bot
.send_message(chat::Id(42), html("<escaped text, sent as html!>"))
.call()
.await
.unwrap();
}
Re-exports
pub use html::html;
pub use markdown_v2::markdown_v2;
Modules
Structs
code_block
.inline_code
.strikethrough
.