package text
import "github.com/yuin/goldmark/text"
Package text provides functionalities to manipulate texts.
Index ¶
- Constants
- type BlockReader
- type FindClosureOptions
- type Reader
- type Segment
- func NewSegment(start, stop int) Segment
- func NewSegmentPadding(start, stop, n int) Segment
- func (t *Segment) Between(other Segment) Segment
- func (t *Segment) ConcatPadding(v []byte) []byte
- func (t *Segment) IsEmpty() bool
- func (t *Segment) Len() int
- func (t *Segment) TrimLeftSpace(buffer []byte) Segment
- func (t *Segment) TrimLeftSpaceWidth(width int, buffer []byte) Segment
- func (t *Segment) TrimRightSpace(buffer []byte) Segment
- func (t *Segment) Value(buffer []byte) []byte
- func (t *Segment) WithStart(v int) Segment
- func (t *Segment) WithStop(v int) Segment
- type Segments
- func NewSegments() *Segments
- func (s *Segments) Append(t Segment)
- func (s *Segments) AppendAll(t []Segment)
- func (s *Segments) At(i int) Segment
- func (s *Segments) Clear()
- func (s *Segments) Len() int
- func (s *Segments) Set(i int, v Segment)
- func (s *Segments) SetSliced(lo, hi int)
- func (s *Segments) Sliced(lo, hi int) []Segment
- func (s *Segments) Unshift(v Segment)
- func (s *Segments) Value(buffer []byte) []byte
Constants ¶
const EOF = byte(0xff)
EOF indicates the end of file.
Types ¶
type BlockReader ¶
type BlockReader interface { Reader // Reset resets current state and sets new segments to the reader. Reset(segment *Segments) }
A BlockReader interface is a reader that is optimized for Blocks.
func NewBlockReader ¶
func NewBlockReader(source []byte, segments *Segments) BlockReader
NewBlockReader returns a new BlockReader.
type FindClosureOptions ¶
type FindClosureOptions struct { // CodeSpan is a flag for the FindClosure. If this is set to true, // FindClosure ignores closers in codespans. CodeSpan bool // Nesting is a flag for the FindClosure. If this is set to true, // FindClosure allows nesting. Nesting bool // Newline is a flag for the FindClosure. If this is set to true, // FindClosure searches for a closer over multiple lines. Newline bool // Advance is a flag for the FindClosure. If this is set to true, // FindClosure advances pointers when closer is found. Advance bool }
FindClosureOptions is options for Reader.FindClosure.
type Reader ¶
type Reader interface { io.RuneReader // Source returns a source of the reader. Source() []byte // ResetPosition resets positions. ResetPosition() // Peek returns a byte at current position without advancing the internal pointer. Peek() byte // PeekLine returns the current line without advancing the internal pointer. PeekLine() ([]byte, Segment) // PrecendingCharacter returns a character just before current internal pointer. PrecendingCharacter() rune // Value returns a value of the given segment. Value(Segment) []byte // LineOffset returns a distance from the line head to current position. LineOffset() int // Position returns current line number and position. Position() (int, Segment) // SetPosition sets current line number and position. SetPosition(int, Segment) // SetPadding sets padding to the reader. SetPadding(int) // Advance advances the internal pointer. Advance(int) // AdvanceAndSetPadding advances the internal pointer and add padding to the // reader. AdvanceAndSetPadding(int, int) // AdvanceLine advances the internal pointer to the next line head. AdvanceLine() // SkipSpaces skips space characters and returns a non-blank line. // If it reaches EOF, returns false. SkipSpaces() (Segment, int, bool) // SkipSpaces skips blank lines and returns a non-blank line. // If it reaches EOF, returns false. SkipBlankLines() (Segment, int, bool) // Match performs regular expression matching to current line. Match(reg *regexp.Regexp) bool // Match performs regular expression searching to current line. FindSubMatch(reg *regexp.Regexp) [][]byte // FindClosure finds corresponding closure. FindClosure(opener, closer byte, options FindClosureOptions) (*Segments, bool) }
A Reader interface provides abstracted method for reading text.
func NewReader ¶
NewReader return a new Reader that can read UTF-8 bytes .
type Segment ¶
type Segment struct { // Start is a start position of the segment. Start int // Stop is a stop position of the segment. // This value should be excluded. Stop int // Padding is a padding length of the segment. Padding int // ForceNewline is true if the segment should be ended with a newline. // Some elements(i.e. CodeBlock, FencedCodeBlock) does not trim trailing // newlines. Spec defines that EOF is treated as a newline, so we need to // add a newline to the end of the segment if it is not empty. // // i.e.: // // ```go // const test = "test" // // This code does not close the code block and ends with EOF. In this case, // we need to add a newline to the end of the last line like `const test = "test"\n`. ForceNewline bool }
A Segment struct holds information about source positions.
func NewSegment ¶
NewSegment return a new Segment.
func NewSegmentPadding ¶
NewSegmentPadding returns a new Segment with the given padding.
func (*Segment) Between ¶
Between returns a segment between this segment and the given segment.
func (*Segment) ConcatPadding ¶
ConcatPadding concats the padding to the given slice.
func (*Segment) IsEmpty ¶
IsEmpty returns true if this segment is empty, otherwise false.
func (*Segment) Len ¶
Len returns a length of the segment.
func (*Segment) TrimLeftSpace ¶
TrimLeftSpace returns a new segment by slicing off all leading space characters including padding.
func (*Segment) TrimLeftSpaceWidth ¶
TrimLeftSpaceWidth returns a new segment by slicing off leading space characters until the given width.
func (*Segment) TrimRightSpace ¶
TrimRightSpace returns a new segment by slicing off all trailing space characters.
func (*Segment) Value ¶
Value returns a value of the segment.
func (*Segment) WithStart ¶
WithStart returns a new Segment with same value except Start.
func (*Segment) WithStop ¶
WithStop returns a new Segment with same value except Stop.
type Segments ¶
type Segments struct {
// contains filtered or unexported fields
}
Segments is a collection of the Segment.
func NewSegments ¶
func NewSegments() *Segments
NewSegments return a new Segments.
func (*Segments) Append ¶
Append appends the given segment after the tail of the collection.
func (*Segments) AppendAll ¶
AppendAll appends all elements of given segments after the tail of the collection.
func (*Segments) At ¶
At returns a segment at the given index.
func (*Segments) Clear ¶
func (s *Segments) Clear()
Clear delete all element of the collection.
func (*Segments) Len ¶
Len returns the length of the collection.
func (*Segments) Set ¶
Set sets the given Segment.
func (*Segments) SetSliced ¶
SetSliced replace the collection with a subsliced value.
func (*Segments) Sliced ¶
Sliced returns a subslice of the collection.
func (*Segments) Unshift ¶
Unshift insert the given Segment to head of the collection.
func (*Segments) Value ¶
Value returns a string value of the collection.
Source Files ¶
package.go reader.go segment.go
- Version
- v1.7.8 (latest)
- Published
- Oct 16, 2024
- Platform
- linux/amd64
- Imports
- 5 packages
- Last checked
- 4 days ago –
Tools for package owners.