pageparser

package
v0.88.1 Latest Latest
Warning

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

Go to latest
Published: Sep 4, 2021 License: Apache-2.0 Imports: 10 Imported by: 36

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

func FormatFromFrontMatterType(typ ItemType) metadecoders.Format

Types

type Config

type Config struct {
	EnableEmoji bool
}

type ContentFrontMatter added in v0.65.0

type ContentFrontMatter struct {
	Content           []byte
	FrontMatter       map[string]interface{}
	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
	Pos  int
	Val  []byte
	// 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) IsInlineShortcodeName

func (i Item) IsInlineShortcodeName() bool

func (Item) IsLeftShortcodeDelim

func (i Item) IsLeftShortcodeDelim() bool

func (Item) IsNonWhitespace

func (i Item) IsNonWhitespace() 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) String

func (i Item) String() string

func (Item) ValStr

func (i Item) ValStr() string

func (Item) ValTyped added in v0.59.0

func (i Item) ValTyped() interface{}

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

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 (*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) Input

func (t *Iterator) Input() []byte

Input returns the input source.

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() 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.

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. TODO(bep) now that we have improved the "lazy order" init, it *may* be some potential saving in doing a buffered approach where the first pass does the frontmatter only.

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