markdown

package
v0.0.0-...-17e4b47 Latest Latest
Warning

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

Go to latest
Published: Mar 27, 2020 License: Apache-2.0 Imports: 18 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

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

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

	// a pair of template's name and its underlying file information
	TemplateFiles map[string]*cachedFileInfo
}

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]interface{}
	Styles  []string
	Scripts []string
	Meta    map[string]string
	Files   []FileInfo
}

Data represents a markdown document.

func (Data) Include

func (d Data) Include(filename string, args ...interface{}) (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
}

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