markdown

package
v0.8.2 Latest Latest
Warning

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

Go to latest
Published: Feb 25, 2016 License: Apache-2.0 Imports: 20 Imported by: 0

Documentation

Overview

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

Index

Constants

View Source
const (
	// DefaultTemplate is the default template.
	DefaultTemplate = "defaultTemplate"
	// DefaultStaticDir is the default static directory.
	DefaultStaticDir = "generated_site"
)
View Source
const DefaultInterval = time.Second * 60

DefaultInterval is the default interval at which the markdown watcher checks for changes.

Variables

This section is empty.

Functions

func GenerateStatic added in v0.7.5

func GenerateStatic(md Markdown, cfg *Config) error

GenerateStatic generate static files and link index from markdowns. It only generates static files if it is enabled (cfg.StaticDir must be set).

func TickerFunc added in v0.7.5

func TickerFunc(interval time.Duration, f func()) chan struct{}

TickerFunc runs f at interval. A message to the returned channel will stop the executing goroutine.

func Watch added in v0.7.5

func Watch(md Markdown, c *Config, interval time.Duration) (stopChan chan struct{})

Watch monitors the configured markdown directory for changes. It calls GenerateLinks when there are changes.

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

	// Links to all markdown pages ordered by date.
	Links []PageLink

	// Directory to store static files
	StaticDir string

	// If in development mode. i.e. Actively editing markdown files.
	Development bool

	sync.RWMutex
	// contains filtered or unexported fields
}

Config stores markdown middleware configurations.

func (*Config) IsValidExt added in v0.7.5

func (c *Config) IsValidExt(ext string) bool

IsValidExt checks to see if an extension is a valid markdown extension for config.

type Data added in v0.8.0

type Data struct {
	middleware.Context
	Doc      map[string]string
	DocFlags map[string]bool
	Links    []PageLink
}

Data represents a markdown document.

type JSONMetadataParser added in v0.7.0

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

JSONMetadataParser is the MetadataParser 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, ctx middleware.Context) ([]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

	// Publish date
	Date time.Time

	// Variables to be used with Template
	Variables map[string]string

	// Flags to be used with Template
	Flags map[string]bool
}

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 PageLink struct {
	Title   string
	Summary string
	Date    time.Time
	URL     string
}

PageLink represents a statically generated markdown page.

type SummaryRenderer added in v0.7.5

type SummaryRenderer struct{}

SummaryRenderer represents a summary renderer.

func (r SummaryRenderer) AutoLink(out *bytes.Buffer, link []byte, kind int)

AutoLink is the autolink tag callback.

func (SummaryRenderer) BlockCode added in v0.7.5

func (r SummaryRenderer) BlockCode(out *bytes.Buffer, text []byte, lang string)

BlockCode is the code tag callback.

func (SummaryRenderer) BlockHtml added in v0.7.5

func (r SummaryRenderer) BlockHtml(out *bytes.Buffer, text []byte)

BlockHtml is the HTML tag callback.

func (SummaryRenderer) BlockQuote added in v0.7.5

func (r SummaryRenderer) BlockQuote(out *bytes.Buffer, text []byte)

BlockQuote is the quote tag callback.

func (SummaryRenderer) CodeSpan added in v0.7.5

func (r SummaryRenderer) CodeSpan(out *bytes.Buffer, text []byte)

CodeSpan is the code span tag callback.

func (SummaryRenderer) DocumentFooter added in v0.7.5

func (r SummaryRenderer) DocumentFooter(out *bytes.Buffer)

DocumentFooter callback.

func (SummaryRenderer) DocumentHeader added in v0.7.5

func (r SummaryRenderer) DocumentHeader(out *bytes.Buffer)

DocumentHeader callback.

func (SummaryRenderer) DoubleEmphasis added in v0.7.5

func (r SummaryRenderer) DoubleEmphasis(out *bytes.Buffer, text []byte)

DoubleEmphasis is the double emphasis tag callback.

func (SummaryRenderer) Emphasis added in v0.7.5

func (r SummaryRenderer) Emphasis(out *bytes.Buffer, text []byte)

Emphasis is the emphasis tag callback.

func (SummaryRenderer) Entity added in v0.7.5

func (r SummaryRenderer) Entity(out *bytes.Buffer, entity []byte)

Entity callback.

func (SummaryRenderer) FootnoteItem added in v0.7.5

func (r SummaryRenderer) FootnoteItem(out *bytes.Buffer, name, text []byte, flags int)

FootnoteItem is the footnote item tag callback.

func (SummaryRenderer) FootnoteRef added in v0.7.5

func (r SummaryRenderer) FootnoteRef(out *bytes.Buffer, ref []byte, id int)

FootnoteRef is the footnote ref tag callback.

func (SummaryRenderer) Footnotes added in v0.7.5

func (r SummaryRenderer) Footnotes(out *bytes.Buffer, text func() bool)

Footnotes is the foot notes tag callback.

func (SummaryRenderer) GetFlags added in v0.7.5

func (r SummaryRenderer) GetFlags() int

GetFlags returns zero.

func (SummaryRenderer) HRule added in v0.7.5

func (r SummaryRenderer) HRule(out *bytes.Buffer)

HRule is the horizontal rule tag callback.

func (SummaryRenderer) Header added in v0.7.5

func (r SummaryRenderer) Header(out *bytes.Buffer, text func() bool, level int, id string)

Header is the header tag callback.

func (SummaryRenderer) Image added in v0.7.5

func (r SummaryRenderer) Image(out *bytes.Buffer, link []byte, title []byte, alt []byte)

Image is the image tag callback.

func (SummaryRenderer) LineBreak added in v0.7.5

func (r SummaryRenderer) LineBreak(out *bytes.Buffer)

LineBreak is the line break tag callback.

func (r SummaryRenderer) Link(out *bytes.Buffer, link []byte, title []byte, content []byte)

Link is the link tag callback.

func (SummaryRenderer) List added in v0.7.5

func (r SummaryRenderer) List(out *bytes.Buffer, text func() bool, flags int)

List is the list tag callback.

func (SummaryRenderer) ListItem added in v0.7.5

func (r SummaryRenderer) ListItem(out *bytes.Buffer, text []byte, flags int)

ListItem is the list item tag callback.

func (SummaryRenderer) NormalText added in v0.7.5

func (r SummaryRenderer) NormalText(out *bytes.Buffer, text []byte)

NormalText callback.

func (SummaryRenderer) Paragraph added in v0.7.5

func (r SummaryRenderer) Paragraph(out *bytes.Buffer, text func() bool)

Paragraph is the paragraph tag callback.

func (SummaryRenderer) RawHtmlTag added in v0.7.5

func (r SummaryRenderer) RawHtmlTag(out *bytes.Buffer, tag []byte)

RawHtmlTag is the raw HTML tag callback.

func (SummaryRenderer) StrikeThrough added in v0.7.5

func (r SummaryRenderer) StrikeThrough(out *bytes.Buffer, text []byte)

StrikeThrough is the strikethrough tag callback.

func (SummaryRenderer) Table added in v0.7.5

func (r SummaryRenderer) Table(out *bytes.Buffer, header []byte, body []byte, columnData []int)

Table is the table tag callback.

func (SummaryRenderer) TableCell added in v0.7.5

func (r SummaryRenderer) TableCell(out *bytes.Buffer, text []byte, flags int)

TableCell is the table cell tag callback.

func (SummaryRenderer) TableHeaderCell added in v0.7.5

func (r SummaryRenderer) TableHeaderCell(out *bytes.Buffer, text []byte, flags int)

TableHeaderCell is the table header cell tag callback.

func (SummaryRenderer) TableRow added in v0.7.5

func (r SummaryRenderer) TableRow(out *bytes.Buffer, text []byte)

TableRow is the table row tag callback.

func (SummaryRenderer) TitleBlock added in v0.7.5

func (r SummaryRenderer) TitleBlock(out *bytes.Buffer, text []byte)

TitleBlock is the title tag callback.

func (SummaryRenderer) TripleEmphasis added in v0.7.5

func (r SummaryRenderer) TripleEmphasis(out *bytes.Buffer, text []byte)

TripleEmphasis is the triple emphasis tag callback.

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