markup

package
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 14, 2020 License: MIT Imports: 6 Imported by: 3

Documentation

Overview

escape and parse markdown elements

Index

Constants

View Source
const (
	NormalText byte = iota
	ColorCode
	ColorText
	ColorTextBold
	ColorTextUnderline
	ColorTextStrike
	ColorTextEmphasis
	UrlLink
	UrlText
	ImagePath
	ImageText
	ImageLink
	BoldText
	StrikeText
	EmphasisText
	UnderlineText
	ErrorText
	EOF
)
View Source
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"
)

Variables

This section is empty.

Functions

func EscapeString

func EscapeString(msg string) string

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 NewCleaner

func NewCleaner(w io.WriteCloser) *Cleaner

Returns a Cleaner

func (*Cleaner) Close

func (c *Cleaner) Close()

Close wraps the underlying WriteCloser's Close method

func (*Cleaner) Write

func (c *Cleaner) Write(msg []byte) (n int, err error)

Write call the underlying WriteCloser's Write method Write does not modify the contents of msg

func (*Cleaner) WriteEscaped

func (c *Cleaner) WriteEscaped(msg []byte) (n int, err error)

WriteEscaped writes the properly escaped markdown to the underlying WriteCloser

func (*Cleaner) WriteHeader

func (c *Cleaner) WriteHeader(degree int, msg []byte) (n int, err error)

Variant of WriteEscaped which writes an nth degree markdown header element to the underlying WriteCloser

func (*Cleaner) WriteList

func (c *Cleaner) WriteList(depth int, msg []byte) (n int, err error)

Variant of WriteEscaped which adds an nth-nested markdown list element to the underlying WriteCloser

func (*Cleaner) WriteString

func (c *Cleaner) WriteString(msg string) (n int, err error)

WriteString is a variant of Write which accepts a string as input

func (*Cleaner) WriteStringEscaped

func (c *Cleaner) WriteStringEscaped(msg string) (n int, err error)

Variant of WriteEscaped which accepts a string as input

func (*Cleaner) Writef

func (c *Cleaner) Writef(format string, args ...interface{}) (n int, err error)

Variant of Write which accepts a format specifier

func (*Cleaner) WritefEscaped

func (c *Cleaner) WritefEscaped(format string, args ...interface{}) (n int, err error)

Variant of WriteEscaped which accepts a format specifier

func (*Cleaner) WritefHeader

func (c *Cleaner) WritefHeader(degree int, format string, args ...interface{}) (n int, err error)

Variant of WriteHeader which accepts a format specifier

func (*Cleaner) WritefList

func (c *Cleaner) WritefList(depth int, format string, args ...interface{}) (n int, err error)

Variant of WriteList 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 hexidecimal form. #000000 to #FFFFFF, as well as #000 to #FFF. No alpha channel support currently exists.

func NewColor

func NewColor(code string, msg []byte) (*Color, error)

NewColor returns a Color Returns error if color code is invalid

func (*Color) String

func (c *Color) String() string

type Image

type Image struct {
	// contains filtered or unexported fields
}

Image represents an image markdown element

func NewImage added in v0.1.0

func NewImage(path, msg, alt []byte) (*Image, error)

NewImage returns an Image If `path` is empty, an error will be returned If both `img` and `alt` are empty, an error will be returned If either `img` or `alt` are empty, one will be substituted for the other

func (*Image) String

func (i *Image) String() string

type Item

type Item struct {
	ItemType byte
	Data     []byte
}

Item is returned from a call to Next() ItemType will be an ItemType

type Lexer

type Lexer struct {
	// contains filtered or unexported fields
}

Lexer allows tokenizing of altid-flavored markdown for client-side parsers

func NewLexer

func NewLexer(src []byte) *Lexer

func NewStringLexer

func NewStringLexer(src string) *Lexer

func (*Lexer) Bytes

func (l *Lexer) Bytes() []byte

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

func (*Lexer) Next

func (l *Lexer) Next() Item

Next() returns the next Item from the tokenizer If ItemType is EOF, any subsequent calls to Next() will panic

func (*Lexer) String

func (l *Lexer) String() string

String is the same as Bytes, but returns a string

type Notifier

type Notifier struct {
	// contains filtered or unexported fields
}

Notifier is a type provided for use with fslib's Notification function

func NewNotifier

func NewNotifier(path, from, msg string) *Notifier

NewNotifier returns a notifier ready for parsing

func (*Notifier) Parse

func (n *Notifier) Parse() (string, string, string)

Parse will properly clean the markdown for the `from` and `msg` elements As well as format the lines to fit the notification idioms expected by clients

type Url added in v0.1.0

type Url struct {
	Link []byte
	Msg  []byte
}

Url represents a link markdown element

func NewUrl added in v0.1.0

func NewUrl(link, msg []byte) (*Url, error)

NewUrl returns a Url If `msg` is empty, the contents of `link` will be used If `link` is empty, an error will be returned There are no assumptions about what link points to But before a beta release there may be a schema imposed

func (*Url) String added in v0.1.0

func (u *Url) String() string

The form will be "[msg](link)"

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL