package parser

import "github.com/gohugoio/hugo/parser"

Index

Constants

const (

	// HTMLLead identifies the start of HTML documents.
	HTMLLead = "<"
	// YAMLLead identifies the start of YAML frontmatter.
	YAMLLead = "-"
	// YAMLDelimUnix identifies the end of YAML front matter on Unix.
	YAMLDelimUnix = "---\n"
	// YAMLDelimDOS identifies the end of YAML front matter on Windows.
	YAMLDelimDOS = "---\r\n"
	// YAMLDelim identifies the YAML front matter delimiter.
	YAMLDelim = "---"
	// TOMLLead identifies the start of TOML front matter.
	TOMLLead = "+"
	// TOMLDelimUnix identifies the end of TOML front matter on Unix.
	TOMLDelimUnix = "+++\n"
	// TOMLDelimDOS identifies the end of TOML front matter on Windows.
	TOMLDelimDOS = "+++\r\n"
	// TOMLDelim identifies the TOML front matter delimiter.
	TOMLDelim = "+++"
	// JSONLead identifies the start of JSON frontmatter.
	JSONLead = "{"
	// HTMLCommentStart identifies the start of HTML comment.
	HTMLCommentStart = "<!--"
	// HTMLCommentEnd identifies the end of HTML comment.
	HTMLCommentEnd = "-->"
	// BOM Unicode byte order marker
	BOM = '\ufeff'
)

Functions

func FormatSanitize

func FormatSanitize(kind string) string

FormatSanitize returns the canonical format name for a given kind.

TODO(bep) move to helpers

func FormatToLeadRune

func FormatToLeadRune(kind string) rune

FormatToLeadRune takes a given format kind and return the leading front matter delimiter.

func HandleJSONData

func HandleJSONData(datum []byte) (interface{}, error)

HandleJSONData unmarshals JSON-encoded datum and returns a Go interface representing the encoded data structure.

func HandleJSONMetaData

func HandleJSONMetaData(datum []byte) (map[string]interface{}, error)

HandleJSONMetaData unmarshals JSON-encoded datum and returns a Go interface representing the encoded data structure.

func HandleOrgMetaData

func HandleOrgMetaData(datum []byte) (map[string]interface{}, error)

HandleOrgMetaData unmarshals org-mode encoded datum and returns a Go interface representing the encoded data structure.

func HandleTOMLMetaData

func HandleTOMLMetaData(datum []byte) (map[string]interface{}, error)

HandleTOMLMetaData unmarshals TOML-encoded datum and returns a Go interface representing the encoded data structure.

func HandleYAMLData

func HandleYAMLData(datum []byte) (interface{}, error)

HandleYAMLData unmarshals YAML-encoded datum and returns a Go interface representing the encoded data structure.

func HandleYAMLMetaData

func HandleYAMLMetaData(datum []byte) (map[string]interface{}, error)

HandleYAMLMetaData unmarshals YAML-encoded datum and returns a Go interface representing the encoded data structure.

func InterfaceToConfig

func InterfaceToConfig(in interface{}, mark rune, w io.Writer) error

InterfaceToConfig encodes a given input based upon the mark and writes to w.

func InterfaceToFrontMatter

func InterfaceToFrontMatter(in interface{}, mark rune, w io.Writer) error

InterfaceToFrontMatter encodes a given input into a frontmatter representation based upon the mark with the appropriate front matter delimiters surrounding the output, which is written to w.

Types

type FrontmatterType

type FrontmatterType struct {
	// Parse decodes content into a Go interface.
	Parse func([]byte) (map[string]interface{}, error)
	// contains filtered or unexported fields
}

FrontmatterType represents a type of frontmatter.

func DetectFrontMatter

func DetectFrontMatter(mark rune) (f *FrontmatterType)

DetectFrontMatter detects the type of frontmatter analysing its first character.

type Page

type Page interface {
	// FrontMatter contains the raw frontmatter with relevant delimiters.
	FrontMatter() []byte

	// Content contains the raw page content.
	Content() []byte

	// IsRenderable denotes that the page should be rendered.
	IsRenderable() bool

	// Metadata returns the unmarshalled frontmatter data.
	Metadata() (map[string]interface{}, error)
}

Page represents a parsed content page.

func ReadFrom

func ReadFrom(r io.Reader) (p Page, err error)

ReadFrom reads the content from an io.Reader and constructs a page.

Source Files

frontmatter.go page.go

Version
v0.42.2
Published
Jun 28, 2018
Platform
darwin/amd64
Imports
14 packages
Last checked
30 minutes ago

Tools for package owners.