Documentation ¶
Overview ¶
Package markup implements an API for escaping markup elements in raw text input.
Cleaner wraps a WriteCloser, and wraps common functions to write properly formatted markup to the Writer - these are the *Escaped variant functions. Cleaner also provides the generic methods "Write" and "WriteString", to write unmodified text to the underlying WriteCloser.
Altid-flavoured markup ¶
Described in more detail in the official document https://altid.github.io/markdown.html Common markup elements are generally easier to insert by hand, but several helper types are provided for more complex elements: color, url, and image; which are described in greater detail in greater detail below.
Index ¶
- Constants
- func EscapeString(msg string) string
- type Cleaner
- func (c *Cleaner) Close()
- func (c *Cleaner) Write(msg []byte) (n int, err error)
- func (c *Cleaner) WriteEscaped(msg []byte) (n int, err error)
- func (c *Cleaner) WriteHeader(degree int, msg []byte) (n int, err error)
- func (c *Cleaner) WriteList(depth int, msg []byte) (n int, err error)
- func (c *Cleaner) WriteString(msg string) (n int, err error)
- func (c *Cleaner) WriteStringEscaped(msg string) (n int, err error)
- func (c *Cleaner) Writef(format string, args ...any) (n int, err error)
- func (c *Cleaner) WritefEscaped(format string, args ...any) (n int, err error)
- func (c *Cleaner) WritefHeader(degree int, format string, args ...any) (n int, err error)
- func (c *Cleaner) WritefList(depth int, format string, args ...any) (n int, err error)
- type Color
- type Image
- type Item
- type Lexer
- type Notifier
- type URL
Examples ¶
Constants ¶
const ( NormalText byte = iota ColorCode ColorText ColorTextBold ColorTextStrong ColorTextStrike ColorTextEmphasis URLLink URLText ImagePath ImageText ImageLink BoldText StrikeText EmphasisText StrongText ErrorText EOF )
The various types of text tokens
const ( White = "white" Black = "black" Blue = "blue" Green = "green" Red = "red" Brown = "brown" Purple = "purple" Orange = "orange" Yellow = "yellow" LightGreen = "lightgreen" Cyan = "cyan" LightCyan = "lightcyan" LightBlue = "lightblue" Pink = "pink" Grey = "grey" LightGrey = "lightgrey" )
Available markup colour codes, feel free to PR your favourite
Variables ¶
This section is empty.
Functions ¶
func EscapeString ¶
EscapeString returns a properly escaped Altid markup string
Types ¶
type Cleaner ¶
type Cleaner struct {
// contains filtered or unexported fields
}
Cleaner represents a WriteCloser used to escape any altid markdown elements from a reader
func (*Cleaner) Close ¶
func (c *Cleaner) Close()
Close wraps the underlying WriteCloser's Close method
func (*Cleaner) Write ¶
Write call the underlying WriteCloser's Write method Write does not modify the contents of msg
func (*Cleaner) WriteEscaped ¶
WriteEscaped writes the properly escaped markdown to the underlying WriteCloser
func (*Cleaner) WriteHeader ¶
WriteHeader is a variant of WriteEscaped which writes an nth degree markdown header element to the underlying WriteCloser
func (*Cleaner) WriteList ¶
WriteList is a variant of WriteEscaped which adds an nth-nested markdown list element to the underlying WriteCloser
func (*Cleaner) WriteString ¶
WriteString is a variant of Write which accepts a string as input
func (*Cleaner) WriteStringEscaped ¶
WriteStringEscaped is a variant of WriteEscaped which accepts a string as input
func (*Cleaner) WritefEscaped ¶
WritefEscaped is a variant of WriteEscaped which accepts a format specifier
func (*Cleaner) WritefHeader ¶
WritefHeader is a variant of WriteHeader which accepts a format specifier
type Color ¶
type Color struct {
// contains filtered or unexported fields
}
Color represents a color markdown element Valid values for code are any [markup constants], or color strings in hexadecimal form. #000000 to #FFFFFF, as well as #000 to #FFF. No alpha channel support currently exists.
type Lexer ¶
type Lexer struct {
// contains filtered or unexported fields
}
Lexer allows tokenizing of altid-flavored markdown for client-side parsers
Example ¶
package main import ( "github.com/altid/libs/markup" ) func main() { l := markup.NewStringLexer("Text with **bold and _strong tags_**") for { n := l.Next() switch n.ItemType { case markup.URLText: case markup.BoldText: case markup.StrongText: case markup.EOF: break } } }
Output:
func NewStringLexer ¶
NewStringLexer takes in a string and returns a ready to run Lexer
func (*Lexer) Bytes ¶
Bytes wil return a parsed byte array from the input with markdown elements cleaned Any URL will be turned from `[some text](someurl)` to `some text (some url)` IMG will be turned from `![some text](someimage)` to `some text (some image)` color tags will be removed and the raw text will be output
type Notifier ¶
type Notifier struct {
// contains filtered or unexported fields
}
Notifier is a type provided for use with fslib's Notification function
func NewNotifier ¶
NewNotifier returns a notifier ready for parsing
type URL ¶
URL represents a link markdown element