markdown

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: May 25, 2015 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Overview

Package markdown is middleware to render markdown files as HTML on-the-fly.

Index

Constants

View Source
const (
	DefaultTemplate  = "defaultTemplate"
	DefaultStaticDir = "generated_site"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Config added in v0.6.0

type Config struct {
	// Markdown renderer
	Renderer blackfriday.Renderer

	// Base path to match
	PathScope string

	// List of extensions to consider as markdown files
	Extensions []string

	// List of style sheets to load for each markdown file
	Styles []string

	// List of JavaScript files to load for each markdown file
	Scripts []string

	// Map of registered templates
	Templates map[string]string

	// Map of request URL to static files generated
	StaticFiles map[string]string

	// Directory to store static files
	StaticDir string
}

Config stores markdown middleware configurations.

type JSONMetadataParser added in v0.7.0

type JSONMetadataParser struct {
	// contains filtered or unexported fields
}

JSONMetadataParser is the MetdataParser for JSON

func (*JSONMetadataParser) Closing added in v0.7.0

func (j *JSONMetadataParser) Closing() []byte

Closing returns the closing identifier JSON metadata

func (*JSONMetadataParser) Metadata added in v0.7.0

func (j *JSONMetadataParser) Metadata() Metadata

Metadata returns parsed metadata. It should be called only after a call to Parse returns without error.

func (*JSONMetadataParser) Opening added in v0.7.0

func (j *JSONMetadataParser) Opening() []byte

Opening returns the opening identifier JSON metadata

func (*JSONMetadataParser) Parse added in v0.7.0

func (j *JSONMetadataParser) Parse(b []byte) ([]byte, error)

Parse the metadata

type Markdown

type Markdown struct {
	// Server root
	Root string

	// Jail the requests to site root with a mock file system
	FileSys http.FileSystem

	// Next HTTP handler in the chain
	Next middleware.Handler

	// The list of markdown configurations
	Configs []Config

	// The list of index files to try
	IndexFiles []string
}

Markdown implements a layer of middleware that serves markdown as HTML.

func (Markdown) IsIndexFile added in v0.7.0

func (md Markdown) IsIndexFile(file string) bool

IsIndexFile checks to see if a file is an index file

func (Markdown) Process added in v0.7.0

func (md Markdown) Process(c Config, requestPath string, b []byte) ([]byte, error)

Process processes the contents of a page in b. It parses the metadata (if any) and uses the template (if found).

func (Markdown) ServeHTTP

func (md Markdown) ServeHTTP(w http.ResponseWriter, r *http.Request) (int, error)

ServeHTTP implements the http.Handler interface.

type Metadata added in v0.7.0

type Metadata struct {
	// Page title
	Title string

	// Page template
	Template string

	// Variables to be used with Template
	Variables map[string]interface{}
}

Metadata stores a page's metadata

type MetadataParser added in v0.7.0

type MetadataParser interface {
	// Opening identifier
	Opening() []byte

	// Closing identifier
	Closing() []byte

	// Parse the metadata.
	// Returns the remaining page contents (Markdown)
	// after extracting metadata
	Parse([]byte) ([]byte, error)

	// Parsed metadata.
	// Should be called after a call to Parse returns no error
	Metadata() Metadata
}

MetadataParser is a an interface that must be satisfied by each parser

type TOMLMetadataParser added in v0.7.0

type TOMLMetadataParser struct {
	// contains filtered or unexported fields
}

TOMLMetadataParser is the MetadataParser for TOML

func (*TOMLMetadataParser) Closing added in v0.7.0

func (t *TOMLMetadataParser) Closing() []byte

Closing returns the closing identifier TOML metadata

func (*TOMLMetadataParser) Metadata added in v0.7.0

func (t *TOMLMetadataParser) Metadata() Metadata

Metadata returns parsed metadata. It should be called only after a call to Parse returns without error.

func (*TOMLMetadataParser) Opening added in v0.7.0

func (t *TOMLMetadataParser) Opening() []byte

Opening returns the opening identifier TOML metadata

func (*TOMLMetadataParser) Parse added in v0.7.0

func (t *TOMLMetadataParser) Parse(b []byte) ([]byte, error)

Parse the metadata

type YAMLMetadataParser added in v0.7.0

type YAMLMetadataParser struct {
	// contains filtered or unexported fields
}

YAMLMetadataParser is the MetadataParser for YAML

func (*YAMLMetadataParser) Closing added in v0.7.0

func (y *YAMLMetadataParser) Closing() []byte

Closing returns the closing identifier YAML metadata

func (*YAMLMetadataParser) Metadata added in v0.7.0

func (y *YAMLMetadataParser) Metadata() Metadata

Metadata returns parsed metadata. It should be called only after a call to Parse returns without error.

func (*YAMLMetadataParser) Opening added in v0.7.0

func (y *YAMLMetadataParser) Opening() []byte

Opening returns the opening identifier YAML metadata

func (*YAMLMetadataParser) Parse added in v0.7.0

func (y *YAMLMetadataParser) Parse(b []byte) ([]byte, error)

Parse the metadata

Jump to

Keyboard shortcuts

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