Skip to content

CodeText

Static class in Oadm.Sdk.Client.Controls · Oadm.Sdk.Client.dll

Detection, pretty-printing and tokenizing behind CodeView (no UI types, testable on its own). JSON and XML are re-indented with 2 spaces; text that does not parse is shown as it is, without highlighting. Texts longer than the highlight limit are shown plain (still pretty-printed up to CodeText.MaxFormatChars).

public static class CodeText
static CodeLanguage Detect(string? text, string? contentType = null)

Language from the content type (“application/json”, “text/xml”, “application/soap+xml”), else from the text itself.

static string? FormatJson(string text)

JSON indented with 2 spaces and LF line ends (non-ASCII kept readable), or null when it does not parse.

static string? FormatXml(string text)

XML (also SOAP) indented with 2 spaces and LF line ends, declaration kept, or null when it does not parse. DTDs are refused.

static CodeDocument Prepare(string? text, CodeLanguage language = Auto, string? contentType = null, bool format = true, int highlightLimit = 524288, bool colorUnparsed = false)

Prepares text for display. format false keeps the text exactly as it is (still highlighted when it parses). colorUnparsed: JSON and XML that do not parse are still colored token by token (the code editor while typing, an HTML body with several elements). Never throws for any input.

static IReadOnlyList<CodeToken> Tokenize(string text, CodeLanguage language)

Tokens of text; adjacent tokens of the same kind separated only by white space are merged.

const int DefaultHighlightLimit = 524288

Default highlight limit: above it the text is shown without colors (keeps the view fast).

const int MaxFormatChars = 4194304

Above this size JSON and XML are not re-indented either.