Module tbot::markup[][src]

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

html

HTML markup utilities.

markdown_v2

MarkdownV2 markup utilities.

Structs

Bold

Formats text in bold. Can be created with bold.

CodeBlock

Formats a block of code. Can be created with code_block.

InlineCode

Formats an inline piece of code. Can be created with inline_code.

Italic

Formats text in italic. Can be created with italic.

Link

Formats a link. Can be created with link or mention.

Raw

Represents a raw string for formatting. Can be created with raw.

Strikethrough

Formats text with strikethrough. Can be created with strikethrough.

Underline

Formats text underlined. Can be created with underline.

Traits

Formattable

A value that can be formatted in all markups.

Functions

bold

Formats text in bold.

code_block

Formats a block of code.

inline_code

Formats an inline piece of code.

italic

Formats text in italic.

link

Creates a link.

mention

Creates a mention by ID.

raw

Creates a raw string for formatting.

strikethrough

Formats text with strikethrough.

underline

Formats text underlined.