[][src]Module tbot::markup

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 strings:

use tbot::markup::markdown_v2;
assert_eq!(
    markdown_v2(message).to_string(),
    "*\\*This is <b\\>old, \r_and this is bold and italic\\!\r_*",
    // the extra `\r`s are needed for correct parsing in edge cases
);

As you can see, you can fearlessly pass any strings to formatters and they'll be automatically properly escaped. Magic!

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.