Documentation ¶
Overview ¶
Package util provides utility functions for the goldmark.
Index ¶
- func BytesToReadOnlyString(b []byte) string
- func DedentPosition(bs []byte, currentPos, width int) (pos, padding int)
- func DedentPositionPadding(bs []byte, currentPos, paddingv, width int) (pos, padding int)
- func EscapeHTML(v []byte) []byte
- func EscapeHTMLByte(b byte) []byte
- func FindClosure(bs []byte, opener, closure byte, codeSpan, allowNesting bool) int
- func FindEmailIndex(b []byte) int
- func FindURLIndex(b []byte) int
- func FirstNonSpacePosition(bs []byte) int
- func IndentPosition(bs []byte, currentPos, width int) (pos, padding int)
- func IndentPositionPadding(bs []byte, currentPos, paddingv, width int) (pos, padding int)
- func IndentWidth(bs []byte, currentPos int) (width, pos int)
- func IsAlphaNumeric(c byte) bool
- func IsBlank(bs []byte) bool
- func IsEscapedPunctuation(source []byte, i int) bool
- func IsHexDecimal(c byte) bool
- func IsNumeric(c byte) bool
- func IsPunct(c byte) bool
- func IsSpace(c byte) bool
- func ReadWhile(source []byte, index [2]int, pred func(byte) bool) (int, bool)
- func ReplaceSpaces(source []byte, repl byte) []byte
- func ResolveEntityNames(source []byte) []byte
- func ResolveNumericReferences(source []byte) []byte
- func StringToReadOnlyBytes(s string) []byte
- func TabWidth(currentPos int) int
- func ToLinkReference(v []byte) string
- func ToRune(source []byte, pos int) rune
- func ToValidRune(v rune) rune
- func TrimLeft(source, b []byte) []byte
- func TrimLeftLength(source, s []byte) int
- func TrimLeftSpace(source []byte) []byte
- func TrimLeftSpaceLength(source []byte) int
- func TrimRight(source, b []byte) []byte
- func TrimRightLength(source, s []byte) int
- func TrimRightSpace(source []byte) []byte
- func TrimRightSpaceLength(source []byte) int
- func URLEscape(v []byte, resolveReference bool) []byte
- func UTF8Len(b byte) int8
- func UnescapePunctuations(source []byte) []byte
- func VisualizeSpaces(bs []byte) []byte
- type BufWriter
- type BytesFilter
- type CopyOnWriteBuffer
- type HTML5Entity
- type PrioritizedSlice
- type PrioritizedValue
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func BytesToReadOnlyString ¶
BytesToReadOnlyString returns a string converted from given bytes.
func DedentPosition ¶
DedentPosition dedents lines by the given width.
func DedentPositionPadding ¶ added in v1.0.8
DedentPositionPadding dedents lines by the given width. This function is mostly same as DedentPosition except this function takes account into additional paddings.
func EscapeHTML ¶
EscapeHTML escapes characters that should be escaped in HTML text.
func EscapeHTMLByte ¶
EscapeHTMLByte returns HTML escaped bytes if the given byte should be escaped, otherwise nil.
func FindClosure ¶
FindClosure returns a position that closes the given opener. If codeSpan is set true, it ignores characters in code spans. If allowNesting is set true, closures correspond to nested opener will be ignored.
func FindEmailIndex ¶
FindEmailIndex returns a stop index value if the given bytes seem an email address.
func FindURLIndex ¶
FindURLIndex returns a stop index value if the given bytes seem an URL. This function is equivalent to [A-Za-z][A-Za-z0-9.+-]{1,31}:[^<>\x00-\x20]* .
func FirstNonSpacePosition ¶
FirstNonSpacePosition returns a potisoin line that is a first nonspace character.
func IndentPosition ¶
IndentPosition searches an indent position with the given width for the given line. If the line contains tab characters, paddings may be not zero. currentPos==0 and width==2:
position: 0 1 [TAB]aaaa width: 1234 5678
width=2 is in the tab character. In this case, IndentPosition returns (pos=1, padding=2)
func IndentPositionPadding ¶ added in v1.0.8
IndentPositionPadding searches an indent position with the given width for the given line. This function is mostly same as IndentPosition except this function takes account into additional paddings.
func IndentWidth ¶
IndentWidth calculate an indent width for the given line.
func IsAlphaNumeric ¶
IsAlphaNumeric returns true if the given character is a alphabet or a numeric, otherwise false.
func IsEscapedPunctuation ¶
IsEscapedPunctuation returns true if caracter at a given index i is an escaped punctuation, otherwise false.
func IsHexDecimal ¶
IsHexDecimal returns true if the given character is a hexdecimal, otherwise false.
func ReplaceSpaces ¶
ReplaceSpaces replaces sequence of spaces with the given repl.
func ResolveEntityNames ¶
ResolveEntityNames resolve entity references like 'ö" .
func ResolveNumericReferences ¶
ResolveNumericReferences resolve numeric references like 'Ӓ" .
func StringToReadOnlyBytes ¶
StringToReadOnlyBytes returns bytes converted from given string.
func ToLinkReference ¶
ToLinkReference convert given bytes into a valid link reference string. ToLinkReference trims leading and trailing spaces and convert into lower case and replace spaces with a single space character.
func ToValidRune ¶
ToValidRune returns 0xFFFD if the given rune is invalid, otherwise v.
func TrimLeft ¶
TrimLeft trims characters in the given s from head of the source. bytes.TrimLeft offers same functionalities, but bytes.TrimLeft allocates new buffer for the result.
func TrimLeftLength ¶
TrimLeftLength returns a length of leading specified characters.
func TrimLeftSpace ¶
TrimLeftSpace returns a subslice of the given string by slicing off all leading space characters.
func TrimLeftSpaceLength ¶
TrimLeftSpaceLength returns a length of leading space characters.
func TrimRightLength ¶
TrimRightLength returns a length of trailing specified characters.
func TrimRightSpace ¶
TrimRightSpace returns a subslice of the given string by slicing off all trailing space characters.
func TrimRightSpaceLength ¶
TrimRightSpaceLength returns a length of trailing space characters.
func URLEscape ¶
URLEscape escape the given URL. If resolveReference is set true:
- unescape punctuations
- resolve numeric references
- resolve entity references
URL encoded values (%xx) are keeped as is.
func UnescapePunctuations ¶
UnescapePunctuations unescapes blackslash escaped punctuations.
func VisualizeSpaces ¶
VisualizeSpaces visualize invisible space characters.
Types ¶
type BufWriter ¶
type BufWriter interface { io.Writer Available() int Buffered() int Flush() error WriteByte(c byte) error WriteRune(r rune) (size int, err error) WriteString(s string) (int, error) }
A BufWriter is a subset of the bufio.Writer .
type BytesFilter ¶ added in v1.1.14
type BytesFilter interface { // Add adds given bytes to this set. Add([]byte) // Contains return true if this set contains given bytes, otherwise false. Contains([]byte) bool // Extend copies this filter and adds given bytes to new filter. Extend(...[]byte) BytesFilter }
BytesFilter is a efficient data structure for checking whether bytes exist or not. BytesFilter is thread-safe.
func NewBytesFilter ¶ added in v1.1.14
func NewBytesFilter(elements ...[]byte) BytesFilter
NewBytesFilter returns a new BytesFilter.
type CopyOnWriteBuffer ¶
type CopyOnWriteBuffer struct {
// contains filtered or unexported fields
}
A CopyOnWriteBuffer is a byte buffer that copies buffer when it need to be changed.
func NewCopyOnWriteBuffer ¶
func NewCopyOnWriteBuffer(buffer []byte) CopyOnWriteBuffer
NewCopyOnWriteBuffer returns a new CopyOnWriteBuffer.
func (*CopyOnWriteBuffer) Bytes ¶
func (b *CopyOnWriteBuffer) Bytes() []byte
Bytes returns bytes of this buffer.
func (*CopyOnWriteBuffer) IsCopied ¶
func (b *CopyOnWriteBuffer) IsCopied() bool
IsCopied returns true if buffer has been copied, otherwise false.
func (*CopyOnWriteBuffer) Write ¶
func (b *CopyOnWriteBuffer) Write(value []byte)
Write writes given bytes to the buffer.
func (*CopyOnWriteBuffer) WriteByte ¶
func (b *CopyOnWriteBuffer) WriteByte(c byte)
WriteByte writes the given byte to the buffer.
type HTML5Entity ¶
An HTML5Entity struct represents HTML5 entitites.
func LookUpHTML5EntityByName ¶
func LookUpHTML5EntityByName(name string) (*HTML5Entity, bool)
LookUpHTML5EntityByName returns (an HTML5Entity, true) if an entity named given name is found, otherwise (nil, false)
type PrioritizedSlice ¶
type PrioritizedSlice []PrioritizedValue
PrioritizedSlice is a slice of the PrioritizedValues
func (PrioritizedSlice) Remove ¶
func (s PrioritizedSlice) Remove(v interface{}) PrioritizedSlice
Remove removes the given value from this slice.
func (PrioritizedSlice) Sort ¶
func (s PrioritizedSlice) Sort()
Sort sorts the PrioritizedSlice in ascending order.
type PrioritizedValue ¶
type PrioritizedValue struct { // Value is an arbitrary value that you want to prioritize. Value interface{} // Priority is a priority of the value. Priority int }
A PrioritizedValue struct holds pair of an arbitrary value and a priority.
func Prioritized ¶
func Prioritized(v interface{}, priority int) PrioritizedValue
Prioritized returns a new PrioritizedValue.