package pageparser
import "github.com/gohugoio/hugo/parser/pageparser"
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 NewIterator(items Items) *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
Functions ¶
func FormatFromFrontMatterType ¶
func FormatFromFrontMatterType(typ ItemType) metadecoders.Format
func HasShortcode ¶
HasShortcode returns true if the given string contains a shortcode.
func IsProbablySourceOfItems ¶
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 Config ¶
type ContentFrontMatter ¶
type ContentFrontMatter struct { Content []byte FrontMatter map[string]any FrontMatterFormat metadecoders.Format }
func ParseFrontMatterAndContent ¶
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) IsDone ¶
func (Item) IsEOF ¶
func (Item) IsError ¶
func (Item) IsFrontMatter ¶
func (Item) IsIndentation ¶
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 ¶
func (Item) IsText ¶
func (Item) Pos ¶
func (Item) ToString ¶
func (Item) Val ¶
func (Item) ValStr ¶
func (Item) ValTyped ¶
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 )
func (ItemType) String ¶
type Items ¶
type Items []Item
func ParseBytes ¶
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 ¶
NewIterator creates a new Iterator.
func (*Iterator) Backup ¶
func (t *Iterator) Backup()
backs up one token.
func (*Iterator) Consume ¶
Consume is a convenience method to consume the next n tokens, but back off Errors and EOF.
func (*Iterator) Current ¶
Current will repeatably return the current item.
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) Next ¶
consumes and returns the next item
func (*Iterator) Peek ¶
look at, but do not consume, the next item repeated, sequential calls will return the same item
func (*Iterator) PeekWalk ¶
PeekWalk will feed the next items in the iterator to walkFn until it returns false.
func (*Iterator) Pos ¶
Pos returns the current position in the input.
type Result ¶
type Result interface { // Iterator returns a new Iterator positioned at the beginning of the parse tree. Iterator() *Iterator // Input returns the input to Parse. Input() []byte }
Result holds the parse result.
func ParseMain ¶
ParseMain parses starting with the main section. Used in tests.
Source Files ¶
doc.go item.go itemtype_string.go pagelexer.go pagelexer_intro.go pagelexer_shortcode.go pageparser.go
- Version
- v0.144.2 (latest)
- Published
- Feb 19, 2025
- Platform
- linux/amd64
- Imports
- 11 packages
- Last checked
- 13 hours ago –
Tools for package owners.