Table of Contents

Class Format

Namespace
Kook
Assembly
Kook.Net.Core.dll

A helper class for formatting characters.

public static class Format
Inheritance
Format
Inherited Members

Methods

BlockQuote(string?, bool)

Formats a string as a block quote as a whole.

public static string BlockQuote(this string? text, bool sanitize = true)

Parameters

text string

The text to format.

sanitize bool

Whether to sanitize the text.

Returns

string

Gets the formatted block quote text.

Remarks

warning

Due to the working mechanism of the KOOK KMarkdown renderer, this method will insert zero-width joiner special characters (\u200d) before the first empty line and between each empty line in the text by default, so that the renderer can display the entire text as a single quote. When the user copies the text inside the quote, they will not copy this special character. However, if you obtain the message text from the server through message-related APIs, it will contain the special character inserted by this method. If you want to disable this feature, please use Quote(string?, bool) instead.

Set sanitize to true will sanitize the text by replacing all occurrences of > with \>.

See Also

Bold(string?, bool)

Returns a markdown-formatted string with bold formatting.

public static string Bold(this string? text, bool sanitize = true)

Parameters

text string

The text to format.

sanitize bool

Whether to sanitize the text.

Returns

string

Gets the formatted text.

Remarks

Set sanitize to true will sanitize the text by replacing all occurrences of * with *.

BoldItalics(string?, bool)

Returns a markdown-formatted string with bold italics formatting.

public static string BoldItalics(this string? text, bool sanitize = true)

Parameters

text string

The text to format.

sanitize bool

Whether to sanitize the text.

Returns

string

Gets the formatted text.

Remarks

Set sanitize to true will sanitize the text by replacing all occurrences of * with *.

Code(string?, string?, bool)

Returns a markdown-formatted string with inline code or code block formatting.

public static string Code(this string? text, string? language = null, bool sanitize = true)

Parameters

text string

The text to format.

language string

The language of the code block.

sanitize bool

Whether to sanitize the text.

Returns

string

Gets the formatted inline code or code block.

Remarks

Set sanitize to true will sanitize the text by replacing all occurrences of </code> with <code>\.

CodeBlock(string?, string?, bool)

Returns a markdown-formatted string with code block formatting.

public static string CodeBlock(this string? text, string? language = null, bool sanitize = true)

Parameters

text string

The text to format.

language string

The language of the code block.

sanitize bool

Whether to sanitize the text.

Returns

string

Gets the formatted code block.

Remarks

Set sanitize to true will sanitize the text by replacing all occurrences of </code> with <code>\.

Colorize(string?, TextTheme, bool)

Returns a markdown-formatted string colored with the specified TextTheme.

public static string Colorize(this string? text, TextTheme theme, bool sanitize = true)

Parameters

text string

The text to colorize.

theme TextTheme

The theme to colorize the text with.

sanitize bool

Whether to sanitize the text.

Returns

string

Gets the colorized text.

Remarks

warning

Colored text is only supported in cards.

Italics(string?, bool)

Returns a markdown-formatted string with italics formatting.

public static string Italics(this string? text, bool sanitize = true)

Parameters

text string

The text to format.

sanitize bool

Whether to sanitize the text.

Returns

string

Gets the formatted text.

Remarks

Set sanitize to true will sanitize the text by replacing all occurrences of * with *.

Quote(string?, bool)

Formats a string as split quotes seperated by multiple new lines.

public static string? Quote(this string? text, bool sanitize = true)

Parameters

text string

The text to format.

sanitize bool

Whether to sanitize the text.

Returns

string

Gets the formatted quote text.

Remarks

warning

Due to the mechanism of the KOOK KMarkdown renderer, this method recognizes multiple text blocks based on two or more consecutive line breaks, and formats each block as a quote. For each text block, a greater than sign (>) and a space is inserted at the beginning of the string, and a zero-width joiner (\u200d) is inserted when the beginning of the block is a whitespace character, to ensure proper display of the quote. When the user copies the text inside the quote, they will not copy this special character. However, if you obtain the message text from the server through message-related APIs, it will contain the special character inserted by this method. An additional line break is also appended at the end of the block to correct any missing line breaks caused by the quote formatting. The appended line break is consistent with the style of the nearby line breaks. To quote the entire text as a whole, use BlockQuote(string?, bool) instead.

Set sanitize to true will sanitize the text by replacing all occurrences of > with \>.

See Also

Sanitize(string?, params string[])

Sanitizes the string, safely escaping any Markdown sequences.

public static string? Sanitize(this string? text, params string[] sensitiveCharacters)

Parameters

text string

The text to sanitize.

sensitiveCharacters string[]

The characters to sanitize.

Returns

string

Gets the sanitized text.

Remarks

If no sensitive characters are specified, the default sensitive characters are used. The default sensitive characters are: </code>, *, ~, `, :, -, ], ), >.

Spoiler(string?, bool)

Returns a string with spoiler formatting.

public static string Spoiler(this string? text, bool sanitize = true)

Parameters

text string

The text to format.

sanitize bool

Whether to sanitize the text.

Returns

string

Gets the formatted spoiled text.

Remarks

Set sanitize to true will sanitize the text by replacing all occurrences of ( and ) with ( and ).

Strikethrough(string?, bool)

Returns a markdown-formatted string with strike-through formatting.

public static string Strikethrough(this string? text, bool sanitize = true)

Parameters

text string

The text to format.

sanitize bool

Whether to sanitize the text.

Returns

string

Gets the formatted text.

Remarks

Set sanitize to true will sanitize the text by replacing all occurrences of ~ with ~.

StripMarkDown(string)

Remove Kook supported markdown from text.

[Obsolete("Use StripMarkdown instead.")]
public static string StripMarkDown(this string text)

Parameters

text string

The text to remove markdown from.

Returns

string

Gets the unformatted text.

StripMarkdown(string)

Remove Kook supported markdown from text.

public static string StripMarkdown(this string text)

Parameters

text string

The text to remove markdown from.

Returns

string

Gets the unformatted text.

Underline(string?, bool)

Returns a markdown-formatted string with underline formatting.

public static string Underline(this string? text, bool sanitize = true)

Parameters

text string

The text to format.

sanitize bool

Whether to sanitize the text.

Returns

string

Gets the formatted underlined text.

Remarks

Set sanitize to true will sanitize the text by replacing all occurrences of ( and ) with ( and ).

Url(string?, string, bool)

Returns a markdown-formatted URL.

public static string Url(this string? text, string url, bool sanitize = true)

Parameters

text string

The text to format.

url string

The URL to format.

sanitize bool

Whether to sanitize the text and URL.

Returns

string

Gets the formatted URL.

Remarks

Set sanitize to true will sanitize the text by replacing all occurrences of [ and ] with [ and ], and the URL by replacing all occurrences of ( and ) with ( and ).

Url(string?, Uri, bool)

Returns a markdown-formatted URL.

public static string Url(this string? text, Uri url, bool sanitize = true)

Parameters

text string

The text to format.

url Uri

The URL to format.

sanitize bool

Whether to sanitize the text and URL.

Returns

string

Gets the formatted URL.

Remarks

Set sanitize to true will sanitize the text by replacing all occurrences of [ and ] with [ and ], and the URL by replacing all occurrences of ( and ) with ( and ).

UsernameAndIdentifyNumber(IUser, bool)

Formats a user's username + identify number while maintaining bidirectional unicode

public static string UsernameAndIdentifyNumber(this IUser user, bool doBidirectional)

Parameters

user IUser

The user whose username and identify number to format.

doBidirectional bool

To format the string in bidirectional unicode or not.

Returns

string

The username#identifyNumber.