caddy: github.com/mholt/caddy/caddyhttp/markdown Index | Files | Directories

package markdown

import "github.com/mholt/caddy/caddyhttp/markdown"

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

Index

Package Files

markdown.go process.go setup.go template.go

func GetDefaultTemplate Uses

func GetDefaultTemplate() *template.Template

GetDefaultTemplate returns the default template.

func SetTemplate Uses

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.

type Config Uses

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 Uses

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 Uses

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 Uses

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 Uses

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 Uses

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 Uses

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 Uses

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

ServeHTTP implements the http.Handler interface.

Directories

PathSynopsis
metadata
summary

Package markdown imports 18 packages (graph) and is imported by 105 packages. Updated 2019-07-02. Refresh now. Tools for package owners.