Documentation ¶
Overview ¶
Package pageparser provides a parser for Hugo content files (Markdown, HTML etc.) in Hugo. This implementation is highly inspired by the great talk given by Rob Pike called "Lexical Scanning in Go" It's on YouTube, Google it!. See slides here: https://go.dev/talks/2011/lex.slide#1
Index ¶
- func FormatFromFrontMatterType(typ ItemType) metadecoders.Format
- func HasShortcode(s string) bool
- func IsProbablySourceOfItems(source []byte, items Items) bool
- type Config
- type ContentFrontMatter
- type Item
- func (i Item) IsDone() bool
- func (i Item) IsEOF() bool
- func (i Item) IsError() bool
- func (i Item) IsFrontMatter() bool
- func (i Item) IsIndentation() bool
- func (i Item) IsInlineShortcodeName() bool
- func (i Item) IsLeftShortcodeDelim() bool
- func (i Item) IsNonWhitespace(source []byte) bool
- func (i Item) IsRightShortcodeDelim() bool
- func (i Item) IsShortcodeClose() bool
- func (i Item) IsShortcodeMarkupDelimiter() bool
- func (i Item) IsShortcodeName() bool
- func (i Item) IsShortcodeParam() bool
- func (i Item) IsShortcodeParamVal() bool
- func (i Item) IsText() bool
- func (i Item) Pos() int
- func (i Item) ToString(source []byte) string
- func (i Item) Val(source []byte) []byte
- func (i Item) ValStr(source []byte) string
- func (i Item) ValTyped(source []byte) any
- type ItemType
- type Items
- type Iterator
- func (t *Iterator) Backup()
- func (t *Iterator) Consume(cnt int)
- func (t *Iterator) Current() Item
- func (t *Iterator) IsValueNext() bool
- func (t *Iterator) LineNumber(source []byte) int
- func (t *Iterator) Next() Item
- func (t *Iterator) Peek() Item
- func (t *Iterator) PeekWalk(walkFn func(item Item) bool)
- func (t *Iterator) Pos() int
- type Result
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func FormatFromFrontMatterType ¶ added in v0.65.0
func FormatFromFrontMatterType(typ ItemType) metadecoders.Format
func HasShortcode ¶ added in v0.111.0
HasShortcode returns true if the given string contains a shortcode.
func IsProbablySourceOfItems ¶ added in v0.102.0
IsProbablySourceOfItems returns true if the given source looks like original source of the items. There may be some false positives, but that is highly unlikely and good enough for the planned purpose. It will also return false if the last item is not EOF (error situations) and true if both source and items are empty.
Types ¶
type ContentFrontMatter ¶ added in v0.65.0
type ContentFrontMatter struct { Content []byte FrontMatter map[string]any FrontMatterFormat metadecoders.Format }
func ParseFrontMatterAndContent ¶ added in v0.65.0
func ParseFrontMatterAndContent(r io.Reader) (ContentFrontMatter, error)
ParseFrontMatterAndContent is a convenience method to extract front matter and content from a content page.
type Item ¶
func (Item) IsFrontMatter ¶
func (Item) IsIndentation ¶ added in v0.100.0
func (Item) IsInlineShortcodeName ¶
func (Item) IsLeftShortcodeDelim ¶
func (Item) IsNonWhitespace ¶
func (Item) IsRightShortcodeDelim ¶
func (Item) IsShortcodeClose ¶
func (Item) IsShortcodeMarkupDelimiter ¶
func (Item) IsShortcodeName ¶
func (Item) IsShortcodeParam ¶
func (Item) IsShortcodeParamVal ¶
type ItemType ¶
type ItemType int
const ( // page items TypeLeadSummaryDivider ItemType // <!--more-->, # more TypeFrontMatterYAML TypeFrontMatterTOML TypeFrontMatterJSON TypeFrontMatterORG TypeIgnore // // The BOM Unicode byte order marker and possibly others )
type Items ¶
type Items []Item
func ParseBytes ¶ added in v0.123.0
ParseBytes parses the page in b according to the given Config.
type Iterator ¶
type Iterator struct {
// contains filtered or unexported fields
}
An Iterator has methods to iterate a parsed page with support going back if needed.
func NewIterator ¶ added in v0.102.0
NewIterator creates a new Iterator.
func (*Iterator) Consume ¶
Consume is a convenience method to consume the next n tokens, but back off Errors and EOF.
func (*Iterator) IsValueNext ¶
check for non-error and non-EOF types coming next
func (*Iterator) LineNumber ¶
LineNumber returns the current line number. Used for logging.
func (*Iterator) Peek ¶
look at, but do not consume, the next item repeated, sequential calls will return the same item