Documentation
¶
Overview ¶
Package text reads text documents as UTF-8, from whatever character set they're in, and writes plain text as Markdown, so it's shown as it is
Index ¶
- Constants
- func Decode(data []byte, cut bool) (string, error)
- func Escape(text string) string
- func HasText(r io.Reader) bool
- func NewReader(r io.Reader) io.Reader
- func PlainText(value string) string
- func Read(r io.Reader) (string, error)
- func WriteCodeBlock(w io.StringWriter, language string, r io.Reader) error
- func WriteLF(w io.StringWriter, r io.Reader) error
- func WriteMarkdown(w io.StringWriter, text string) error
- func WriteMarkdownFrom(w io.StringWriter, r io.Reader) error
Constants ¶
const ( // MaxBytes is the most of a text document which is read, as the // document is decoded, or parsed, in memory. A larger document is read // up to this size. MaxBytes = 16 << 20 )
Variables ¶
This section is empty.
Functions ¶
func Decode ¶
Decode returns the text as UTF-8, from the character set of its byte order mark, or UTF-8 when it's valid UTF-8, or else Windows-1252. When the text was cut off, a character cut off at its end is removed first, so it isn't read as invalid UTF-8.
func Escape ¶
Escape returns the text as Markdown within a line, such as a cell of a table, with its characters which are Markdown escaped, and its line breaks and tabs as spaces
func HasText ¶ added in v1.0.6
HasText returns true when the start of the text has a character which isn't white space, and no NUL, as text which is binary has, which is read without moving r, when it can be read at an offset, as a handler's input can
func NewReader ¶ added in v1.0.6
NewReader returns a reader of the text as UTF-8, as it's read, so a text of any size is read a part at a time, rather than in memory: from the character set of its byte order mark, or UTF-8 when its start is valid UTF-8, or else Windows-1252, as Decode does. Sequences of UTF-8 which aren't valid, after its start, are replaced. When its start can't be read, the reader returns the error.
func PlainText ¶
PlainText returns text which may be HTML, such as a description, as plain text, without its tags, with its entities decoded, and its spaces collapsed
func Read ¶
Read returns at most MaxBytes of the text as UTF-8, from the character set of its byte order mark, or UTF-8 when it's valid UTF-8, or else Windows-1252
func WriteCodeBlock ¶ added in v1.0.6
WriteCodeBlock writes the text read from r as a fenced Markdown code block in the language, as CodeBlock returns it, as it's read, so it stops reading when a write returns an error. Its fence is longer than any run of backticks in the text, which it's read for first, when r can seek, or else it's read in memory, up to MaxBytes.
func WriteLF ¶ added in v1.0.6
func WriteLF(w io.StringWriter, r io.Reader) error
WriteLF writes the text read from r to w, without its carriage returns before line feeds, as it's read, so it stops reading when a write returns an error
func WriteMarkdown ¶
func WriteMarkdown(w io.StringWriter, text string) error
WriteMarkdown writes the text as Markdown, a line at a time, so it's shown as it is: its characters which are Markdown are escaped, its line breaks are kept, a blank line separates its paragraphs, and its indentation is kept without the line being code. It stops when a write returns an error.
func WriteMarkdownFrom ¶ added in v1.0.6
func WriteMarkdownFrom(w io.StringWriter, r io.Reader) error
WriteMarkdownFrom writes the text read from r as Markdown, as WriteMarkdown does, a character at a time, as it's read, so it stops reading when a write returns an error, such as when the writer has the part of the Markdown it keeps. Only white space, and digits at the start of a line, are held in memory, rather than a line, so the memory used doesn't grow with the length of a line.
Types ¶
This section is empty.