View Source Telegex.Tools (Telegex v1.8.0)

Some utility functions.

Summary

Functions

Generate a secret token string.

Generate safe Markdown content.

Types

@type markdown_from() :: :text | :inline_link | :pre | :code | :pre_or_code

Functions

Link to this function

gen_secret_token(bytes_count \\ 16)

View Source
@spec gen_secret_token(non_neg_integer()) :: String.t()

Generate a secret token string.

By default, it generates 16 bytes of data and converts it to a 16-digit hexadecimal string (32 characters long). The bytes_count parameter can be passed to control the length of the generated string.

@spec safe_html(String.t()) :: String.t()
Link to this function

safe_markdown(conetnt, from \\ :text)

View Source
@spec safe_markdown(String.t(), markdown_from()) :: String.t()

Generate safe Markdown content.

Examples

iex> Telegex.Tools.safe_markdown("'_', '*', '[', ']', '(', ')', '~', '`', '>', '#', '+', '-', '=', '|', '{', '}', '.', '!'")
~S"'\_', '\*', '\[', '\]', '\(', '\)', '\~', '\`', '\>', '\#', '\+', '\-', '\=', '\|', '\{', '\}', '\.', '\!'"
iex> Telegex.Tools.safe_markdown(~S{https://t.me\)}, :inline_link)
~S|https://t.me\\\)|
iex> Telegex.Tools.safe_markdown(~S{IO.puts `Hello`}, :pre_or_code)
~S|IO.puts \`Hello\`|