pageparser

package
v0.125.6 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 5, 2024 License: Apache-2.0 Imports: 11 Imported by: 34

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

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

func HasShortcode(s string) bool

HasShortcode returns true if the given string contains a shortcode.

func IsProbablySourceOfItems added in v0.102.0

func IsProbablySourceOfItems(source []byte, items Items) bool

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 Config struct{}

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

type Item struct {
	Type ItemType
	Err  error
	// contains filtered or unexported fields
}

func (Item) IsDone

func (i Item) IsDone() bool

func (Item) IsEOF

func (i Item) IsEOF() bool

func (Item) IsError

func (i Item) IsError() bool

func (Item) IsFrontMatter

func (i Item) IsFrontMatter() bool

func (Item) IsIndentation added in v0.100.0

func (i Item) IsIndentation() bool

func (Item) IsInlineShortcodeName

func (i Item) IsInlineShortcodeName() bool

func (Item) IsLeftShortcodeDelim

func (i Item) IsLeftShortcodeDelim() bool

func (Item) IsNonWhitespace

func (i Item) IsNonWhitespace(source []byte) bool

func (Item) IsRightShortcodeDelim

func (i Item) IsRightShortcodeDelim() bool

func (Item) IsShortcodeClose

func (i Item) IsShortcodeClose() bool

func (Item) IsShortcodeMarkupDelimiter

func (i Item) IsShortcodeMarkupDelimiter() bool

func (Item) IsShortcodeName

func (i Item) IsShortcodeName() bool

func (Item) IsShortcodeParam

func (i Item) IsShortcodeParam() bool

func (Item) IsShortcodeParamVal

func (i Item) IsShortcodeParamVal() bool

func (Item) IsText

func (i Item) IsText() bool

func (Item) Pos

func (i Item) Pos() int

func (Item) ToString added in v0.102.0

func (i Item) ToString(source []byte) string

func (Item) Val

func (i Item) Val(source []byte) []byte

func (Item) ValStr

func (i Item) ValStr(source []byte) string

func (Item) ValTyped added in v0.59.0

func (i Item) ValTyped(source []byte) any

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 added in v0.55.0

func (i ItemType) String() string

type Items

type Items []Item

func ParseBytes added in v0.123.0

func ParseBytes(b []byte, cfg Config) (Items, error)

ParseBytes parses the page in b according to the given Config.

func ParseBytesMain added in v0.123.0

func ParseBytesMain(b []byte, cfg Config) (Items, error)

ParseBytesMain parses b starting with the main section.

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

func NewIterator(items Items) *Iterator

NewIterator creates a new Iterator.

func (*Iterator) Backup

func (t *Iterator) Backup()

backs up one token.

func (*Iterator) Consume

func (t *Iterator) Consume(cnt int)

Consume is a convenience method to consume the next n tokens, but back off Errors and EOF.

func (*Iterator) Current added in v0.55.0

func (t *Iterator) Current() Item

Current will repeatably return the current item.

func (*Iterator) IsValueNext

func (t *Iterator) IsValueNext() bool

check for non-error and non-EOF types coming next

func (*Iterator) LineNumber

func (t *Iterator) LineNumber(source []byte) int

LineNumber returns the current line number. Used for logging.

func (*Iterator) Next

func (t *Iterator) Next() Item

consumes and returns the next item

func (*Iterator) Peek

func (t *Iterator) Peek() Item

look at, but do not consume, the next item repeated, sequential calls will return the same item

func (*Iterator) PeekWalk

func (t *Iterator) PeekWalk(walkFn func(item Item) bool)

PeekWalk will feed the next items in the iterator to walkFn until it returns false.

func (*Iterator) Pos added in v0.100.0

func (t *Iterator) Pos() int

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 added in v0.55.0

func ParseMain(r io.Reader, cfg Config) (Result, error)

ParseMain parses starting with the main section. Used in tests.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL