markdown

package
v0.9.1 Latest Latest
Warning

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

Go to latest
Published: Aug 17, 2016 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Overview

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

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetDefaultTemplate

func GetDefaultTemplate() *template.Template

GetDefaultTemplate returns the default template.

func SetTemplate

func SetTemplate(t *template.Template, name, filename string) error

SetTemplate reads in the template with the filename provided. If the file does not exist or is not parsable, it will return an error.

Types

type Config

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

	// Base path to match
	PathScope string

	// List of extensions to consider as markdown files
	Extensions map[string]struct{}

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

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

	// Template(s) to render with
	Template *template.Template
}

Config stores markdown middleware configurations.

func (*Config) Markdown

func (c *Config) Markdown(title string, r io.Reader, dirents []os.FileInfo, ctx httpserver.Context) ([]byte, error)

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

type Data

type Data struct {
	httpserver.Context
	Doc      map[string]string
	DocFlags map[string]bool
	Styles   []string
	Scripts  []string
	Files    []FileInfo
}

Data represents a markdown document.

func (Data) Include

func (d Data) Include(filename string) (string, error)

Include "overrides" the embedded httpserver.Context's Include() method so that included files have access to d's fields. Note: using {{template 'template-name' .}} instead might be better.

type FileInfo

type FileInfo struct {
	os.FileInfo
	// contains filtered or unexported fields
}

FileInfo represents a file in a particular server context. It wraps the os.FileInfo struct.

func (FileInfo) Summarize

func (f FileInfo) Summarize(wordcount int) (string, error)

Summarize returns an abbreviated string representation of the markdown stored in this file. wordcount is the number of words returned in the summary.

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 httpserver.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) ServeHTTP

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

ServeHTTP implements the http.Handler interface.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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