markdown: github.com/knieriem/markdown Index | Files | Directories

package markdown

import "github.com/knieriem/markdown"

A translation of peg-markdown [1] into Go.

Usage example:

package main

import (
	"github.com/knieriem/markdown"
	"os"
	"bufio"
)

func main() {
	p := markdown.NewParser(&markdown.Extensions{Smart: true})

	w := bufio.NewWriter(os.Stdout)
	p.Markdown(os.Stdin, markdown.ToHTML(w))
	w.Flush()
}

[1]: https://github.com/jgm/peg-markdown/

Index

Package Files

doc.go elemheap.go markdown.go out-groffmm.go output.go parser.leg.go

Constants

const (
    LIST = iota /* A generic list of values. For ordered and bullet lists, see below. */
    RAW         /* Raw markdown to be processed further */
    SPACE
    LINEBREAK
    ELLIPSIS
    EMDASH
    ENDASH
    APOSTROPHE
    SINGLEQUOTED
    DOUBLEQUOTED
    STR
    LINK
    IMAGE
    CODE
    HTML
    EMPH
    STRONG
    STRIKE
    PLAIN
    PARA
    LISTITEM
    BULLETLIST
    ORDEREDLIST
    H1  /* Code assumes that H1..6 are in order. */
    H2
    H3
    H4
    H5
    H6
    BLOCKQUOTE
    VERBATIM
    HTMLBLOCK
    HRULE
    REFERENCE
    NOTE
    DEFINITIONLIST
    DEFTITLE
    DEFDATA
)

Types of semantic values returned by parsers.

const (
    TABSTOP = 4
)

type Extensions Uses

type Extensions struct {
    Smart        bool
    Notes        bool
    FilterHTML   bool
    FilterStyles bool
    Strike       bool
    Dlists       bool
}

Markdown Extensions.

type Formatter Uses

type Formatter interface {
    FormatBlock(*element)
    Finish()
}

A Formatter is called repeatedly, one Markdown block at a time, while the document is parsed. At the end of a document the Finish method is called, which may, for example, print footnotes. A Formatter can be reused.

func ToGroffMM Uses

func ToGroffMM(w Writer) Formatter

Returns a formatter that writes the document in groff mm format.

func ToHTML Uses

func ToHTML(w Writer) Formatter

type Parser Uses

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

func NewParser Uses

func NewParser(x *Extensions) (p *Parser)

NewParser creates an instance of a parser. It can be reused so that stacks and buffers need not be allocated anew for each Markdown call.

func (*Parser) Markdown Uses

func (p *Parser) Markdown(src io.Reader, f Formatter)

Markdown parses input from an io.Reader into a tree, and sends parsed blocks to a Formatter

type Writer Uses

type Writer interface {
    Write([]byte) (int, error)
    WriteString(string) (int, error)
    WriteRune(rune) (int, error)
    WriteByte(byte) error
}

Directories

PathSynopsis
cmd/markdown

Package markdown imports 6 packages (graph) and is imported by 22 packages. Updated 2016-07-19. Refresh now. Tools for package owners.