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)deprecated
- func DedentPositionPadding(bs []byte, currentPos, paddingv, width int) (pos, padding int)deprecated
- func DoFullUnicodeCaseFolding(v []byte) []byte
- func EastAsianWidth(r rune) string
- func EscapeHTML(v []byte) []byte
- func EscapeHTMLByte(b byte) []byte
- func FindClosure(bs []byte, opener, closure byte, codeSpan, allowNesting bool) intdeprecated
- 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 IsEastAsianWideRune(r rune) bool
- func IsEscapedPunctuation(source []byte, i int) bool
- func IsHexDecimal(c byte) bool
- func IsNumeric(c byte) bool
- func IsPunct(c byte) bool
- func IsPunctRune(r rune) bool
- func IsSpace(c byte) bool
- func IsSpaceDiscardingUnicodeRune(r rune) bool
- func IsSpaceRune(r rune) 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) (bs []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
- func (b *CopyOnWriteBuffer) Append(value []byte)
- func (b *CopyOnWriteBuffer) AppendByte(c byte)
- func (b *CopyOnWriteBuffer) AppendString(value string)
- func (b *CopyOnWriteBuffer) Bytes() []byte
- func (b *CopyOnWriteBuffer) IsCopied() bool
- func (b *CopyOnWriteBuffer) Write(value []byte)
- func (b *CopyOnWriteBuffer) WriteByte(c byte) error
- func (b *CopyOnWriteBuffer) WriteString(value string)
- 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
deprecated
func DedentPositionPadding
deprecated
DedentPositionPadding dedents lines by the given width. This function is mostly same as DedentPosition except this function takes account into additional paddings.
Deprecated: This function has bugs. Use util.IndentPositionPadding and util.FirstNonSpacePosition.
func DoFullUnicodeCaseFolding ¶
DoFullUnicodeCaseFolding performs full unicode case folding to given bytes.
func EastAsianWidth ¶
EastAsianWidth returns the east asian width of the given rune. See https://www.unicode.org/reports/tr11/tr11-36.html
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
deprecated
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.
Deprecated: This function can not handle newlines. Many elements can be existed over multiple lines(e.g. link labels). Use text.Reader.FindClosure.
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 position 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 ¶
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 IsEastAsianWideRune ¶
IsEastAsianWideRune returns trhe if the given rune is an east asian wide character, otherwise false.
func IsEscapedPunctuation ¶
IsEscapedPunctuation returns true if character 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 IsPunctRune ¶
IsPunctRune returns true if the given rune is a punctuation, otherwise false.
func IsSpaceDiscardingUnicodeRune ¶
IsSpaceDiscardingUnicodeRune returns true if the given rune is space-discarding unicode character, otherwise false. See https://www.w3.org/TR/2020/WD-css-text-3-20200429/#space-discard-set
func IsSpaceRune ¶
IsSpaceRune returns true if the given rune is a space, 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 converts given bytes into a valid link reference string. ToLinkReference performs unicode case folding, trims leading and trailing spaces, converts 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 kept 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 ¶
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 ¶
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) Append ¶
func (b *CopyOnWriteBuffer) Append(value []byte)
Append appends given bytes to the buffer. Append copy buffer at the first time.
func (*CopyOnWriteBuffer) AppendByte ¶
func (b *CopyOnWriteBuffer) AppendByte(c byte)
AppendByte appends given bytes to the buffer. AppendByte copy buffer at the first time.
func (*CopyOnWriteBuffer) AppendString ¶
func (b *CopyOnWriteBuffer) AppendString(value string)
AppendString appends given string to the buffer. AppendString copy buffer at the first time.
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. Write allocate new buffer and clears it at the first time.
func (*CopyOnWriteBuffer) WriteByte ¶
func (b *CopyOnWriteBuffer) WriteByte(c byte) error
WriteByte writes the given byte to the buffer. WriteByte allocate new buffer and clears it at the first time.
func (*CopyOnWriteBuffer) WriteString ¶
func (b *CopyOnWriteBuffer) WriteString(value string)
WriteString writes given string to the buffer. WriteString allocate new buffer and clears it at the first time.
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.