pageparser

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Dec 20, 2022 License: Apache-2.0 Imports: 11 Imported by: 0

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: http://cuddle.googlecode.com/hg/talk/lex.html

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FormatFromFrontMatterType

func FormatFromFrontMatterType(typ ItemType) metadecoders.Format

func IsProbablySourceOfItems

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 {
	EnableEmoji bool
}

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

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

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

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

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

type ItemType

type ItemType int
const (

	// page items
	TypeLeadSummaryDivider ItemType // <!--more-->,  # more
	TypeFrontMatterYAML
	TypeFrontMatterTOML
	TypeFrontMatterJSON
	TypeFrontMatterORG
	TypeEmoji
	TypeIgnore // // The BOM Unicode byte order marker and possibly others

)

func (ItemType) String

func (i ItemType) String() string

type Items

type Items []Item

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

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

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

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 Parse

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

Parse parses the page in the given reader according to the given Config.

func ParseMain

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