Documentation ¶
Index ¶
- func DefaultRenderer(w http.ResponseWriter, r *http.Request, mdf *MarkdownFile)
- func New(prefix string, fs http.FileSystem, renderer Renderer) http.Handler
- func NewMiddleware(prefix string, fs http.FileSystem, renderer Renderer) func(next http.Handler) http.Handler
- type Markdown
- type MarkdownFile
- type Renderer
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DefaultRenderer ¶
func DefaultRenderer(w http.ResponseWriter, r *http.Request, mdf *MarkdownFile)
DefaultRenderer satisfies the Renderer type, and can be used with New() and NewMiddleware().
func New ¶
New returns a new markdown renderer. Prefix is url path to strip from the URL. fs is the filesystem you want to use, and renderer is an optional custom renderer (default uses DefaultRenderer). New() differs from NewMiddleware() in that New() only allows rendering markdown files, and will not serve other static files.
func NewMiddleware ¶
func NewMiddleware(prefix string, fs http.FileSystem, renderer Renderer) func(next http.Handler) http.Handler
NewMiddleware is like New() however it allows serving non-markdown files. Note that because this is a middleware, if the middleware encounters a markdown file, it doesn't continue executing the middleware chain, and will return early. Make sure to have this be the last middleware in the chain to have all of middleware ahead of this get executed properly for pages with markdown content on them.
Types ¶
type Markdown ¶
type Markdown struct {
// contains filtered or unexported fields
}
Markdown is an instantiated handler.
type MarkdownFile ¶
type MarkdownFile struct { Title string Path string FileInfo os.FileInfo Content []byte // contains filtered or unexported fields }
MarkdownFile contains all of the necessary components to render the markdown file.
func (*MarkdownFile) Body ¶
func (mdf *MarkdownFile) Body() template.HTML
Body returns a template.HTML wrapped HTML representation of the Markdown body.
func (*MarkdownFile) GetAttr ¶
func (mdf *MarkdownFile) GetAttr(name string) string
GetAttr gets one of the attributes (metadata) which was defined at the top of the markdown file. For example, you can pull "Created" or "Title" from the following example:
Created: <some date> Title: Example Page ## Your Markdown Here
func (*MarkdownFile) HTML ¶
func (mdf *MarkdownFile) HTML() (toc, body string)
HTML returns the rendered HTML version of the markdown file, by default sanitized ith UGC policies (bluemonday), and common markdown format (blackfriday).
func (*MarkdownFile) TOC ¶
func (mdf *MarkdownFile) TOC() template.HTML
TOC returns a template.HTML wrapped HTML representation of the Markdown table of contents.
type Renderer ¶
type Renderer func(w http.ResponseWriter, r *http.Request, mdr *MarkdownFile)
Renderer is the render function type which is used by the Markdown middleware. This allows you to customize how the markdown is rendered (e.g. you could use your own template wrapping, or custom styles). See the source code for DefaultRenderer for how you would implement this.