markdown

package module
v0.0.0-...-0bf8f97 Latest Latest
Warning

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

Go to latest
Published: Mar 6, 2024 License: BSD-3-Clause Imports: 9 Imported by: 4

README

Package markdown is a Commonmark-compliant Markdown parser and HTML generator. It does not have many bells and whistles, but it does expose the parsed syntax in an easy-to-use form.

Work in progress.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ToHTML

func ToHTML(b Block) string

func ToMarkdown

func ToMarkdown(b Block) string

Types

type AutoLink struct {
	Text string
	URL  string
}

func (*AutoLink) Inline

func (*AutoLink) Inline()

func (*AutoLink) PrintHTML

func (x *AutoLink) PrintHTML(buf *bytes.Buffer)

func (*AutoLink) PrintText

func (x *AutoLink) PrintText(buf *bytes.Buffer)

type Block

type Block interface {
	Pos() Position
	PrintHTML(buf *bytes.Buffer)
	// contains filtered or unexported methods
}

Block is implemented by:

CodeBLock
Document
Empty
HTMLBlock
Heading
Item
List
Paragraph
Quote
Text
ThematicBreak

type Code

type Code struct {
	Text string
}

func (*Code) Inline

func (*Code) Inline()

func (*Code) PrintHTML

func (x *Code) PrintHTML(buf *bytes.Buffer)

func (*Code) PrintText

func (x *Code) PrintText(buf *bytes.Buffer)

type CodeBlock

type CodeBlock struct {
	Position
	Fence string
	Info  string
	Text  []string
}

func (*CodeBlock) PrintHTML

func (b *CodeBlock) PrintHTML(buf *bytes.Buffer)

type Del

type Del struct {
	Marker string
	Inner  []Inline
}

func (*Del) Inline

func (x *Del) Inline()

func (*Del) PrintHTML

func (x *Del) PrintHTML(buf *bytes.Buffer)

func (*Del) PrintText

func (x *Del) PrintText(buf *bytes.Buffer)

type Document

type Document struct {
	Position
	Blocks []Block
	Links  map[string]*Link
}

func (*Document) PrintHTML

func (b *Document) PrintHTML(buf *bytes.Buffer)

type Emoji

type Emoji struct {
	Name string // emoji :name:, including colons
	Text string // Unicode for emoji sequence
}

func (*Emoji) Inline

func (*Emoji) Inline()

func (*Emoji) PrintHTML

func (x *Emoji) PrintHTML(buf *bytes.Buffer)

func (*Emoji) PrintText

func (x *Emoji) PrintText(buf *bytes.Buffer)

type Emph

type Emph struct {
	Marker string
	Inner  []Inline
}

func (*Emph) Inline

func (*Emph) Inline()

func (*Emph) PrintHTML

func (x *Emph) PrintHTML(buf *bytes.Buffer)

func (*Emph) PrintText

func (x *Emph) PrintText(buf *bytes.Buffer)

type Empty

type Empty struct {
	Position
}

func (*Empty) PrintHTML

func (b *Empty) PrintHTML(buf *bytes.Buffer)

type Escaped

type Escaped struct {
	Plain
}

type HTMLBlock

type HTMLBlock struct {
	Position
	Text []string
}

func (*HTMLBlock) PrintHTML

func (b *HTMLBlock) PrintHTML(buf *bytes.Buffer)

type HTMLTag

type HTMLTag struct {
	Text string
}

func (*HTMLTag) Inline

func (*HTMLTag) Inline()

func (*HTMLTag) PrintHTML

func (x *HTMLTag) PrintHTML(buf *bytes.Buffer)

func (*HTMLTag) PrintText

func (x *HTMLTag) PrintText(buf *bytes.Buffer)

type HardBreak

type HardBreak struct{}

func (*HardBreak) Inline

func (*HardBreak) Inline()

func (*HardBreak) PrintHTML

func (x *HardBreak) PrintHTML(buf *bytes.Buffer)

func (*HardBreak) PrintText

func (x *HardBreak) PrintText(buf *bytes.Buffer)

type Heading

type Heading struct {
	Position
	Level int
	Text  *Text
	// The HTML id attribute. The parser populates this field if
	// [Parser.HeadingIDs] is true and the heading ends with text like "{#id}".
	ID string
}

func (*Heading) PrintHTML

func (b *Heading) PrintHTML(buf *bytes.Buffer)

type Image

type Image struct {
	Inner     []Inline
	URL       string
	Title     string
	TitleChar byte
	// contains filtered or unexported fields
}

func (*Image) Inline

func (*Image) Inline()

func (*Image) PrintHTML

func (x *Image) PrintHTML(buf *bytes.Buffer)

func (*Image) PrintText

func (x *Image) PrintText(buf *bytes.Buffer)

type Inline

type Inline interface {
	PrintHTML(*bytes.Buffer)
	PrintText(*bytes.Buffer)
	// contains filtered or unexported methods
}

type Item

type Item struct {
	Position
	Blocks []Block
	// contains filtered or unexported fields
}

func (*Item) PrintHTML

func (b *Item) PrintHTML(buf *bytes.Buffer)
type Link struct {
	Inner     []Inline
	URL       string
	Title     string
	TitleChar byte // ', " or )
	// contains filtered or unexported fields
}

func (*Link) Inline

func (*Link) Inline()

func (*Link) PrintHTML

func (x *Link) PrintHTML(buf *bytes.Buffer)

func (*Link) PrintText

func (x *Link) PrintText(buf *bytes.Buffer)

type List

type List struct {
	Position
	Bullet rune
	Start  int
	Loose  bool
	Items  []Block // always *Item
}

func (*List) PrintHTML

func (b *List) PrintHTML(buf *bytes.Buffer)

type Paragraph

type Paragraph struct {
	Position
	Text *Text
}

func (*Paragraph) PrintHTML

func (b *Paragraph) PrintHTML(buf *bytes.Buffer)

type Parser

type Parser struct {
	// HeadingIDs determines whether the parser accepts
	// the {#hdr} syntax for an HTML id="hdr" attribute on headings.
	// For example, if HeadingIDs is true then the Markdown
	//    ## Overview {#overview}
	// will render as the HTML
	//    <h2 id="overview">Overview</h2>
	HeadingIDs bool

	// Strikethrough determines whether the parser accepts
	// ~abc~ and ~~abc~~ as strikethrough syntax, producing
	// <del>abc</del> in HTML.
	Strikethrough bool

	// TaskListItems determines whether the parser accepts
	// “task list items” as defined in GitHub Flavored Markdown.
	// When a list item begins with the plain text [ ] or [x]
	// that turns into an unchecked or checked check box.
	TaskListItems bool

	// TODO
	AutoLinkText       bool
	AutoLinkAssumeHTTP bool

	// TODO
	Table bool

	// TODO
	Emoji bool

	// TODO
	SmartDot   bool
	SmartDash  bool
	SmartQuote bool
}

A Parser is a Markdown parser. The exported fields in the struct can be filled in before calling Parser.Parse in order to customize the details of the parsing process. A Parser is safe for concurrent use by multiple goroutines.

func (*Parser) Parse

func (p *Parser) Parse(text string) *Document

type Plain

type Plain struct {
	Text string
}

func (*Plain) Inline

func (*Plain) Inline()

func (*Plain) PrintHTML

func (x *Plain) PrintHTML(buf *bytes.Buffer)

func (*Plain) PrintText

func (x *Plain) PrintText(buf *bytes.Buffer)

type Position

type Position struct {
	StartLine int
	EndLine   int
}

func (Position) Pos

func (p Position) Pos() Position

type Quote

type Quote struct {
	Position
	Blocks []Block
}

func (*Quote) PrintHTML

func (b *Quote) PrintHTML(buf *bytes.Buffer)

type SoftBreak

type SoftBreak struct{}

func (*SoftBreak) Inline

func (*SoftBreak) Inline()

func (*SoftBreak) PrintHTML

func (x *SoftBreak) PrintHTML(buf *bytes.Buffer)

func (*SoftBreak) PrintText

func (x *SoftBreak) PrintText(buf *bytes.Buffer)

type Strong

type Strong struct {
	Marker string
	Inner  []Inline
}

func (*Strong) Inline

func (x *Strong) Inline()

func (*Strong) PrintHTML

func (x *Strong) PrintHTML(buf *bytes.Buffer)

func (*Strong) PrintText

func (x *Strong) PrintText(buf *bytes.Buffer)

type Table

type Table struct {
	Position
	Header []*Text
	Align  []string // 'l', 'c', 'r' for left, center, right; 0 for unset
	Rows   [][]*Text
}

func (*Table) PrintHTML

func (t *Table) PrintHTML(buf *bytes.Buffer)

type Task

type Task struct {
	Checked bool
}

func (*Task) Inline

func (x *Task) Inline()

func (*Task) PrintHTML

func (x *Task) PrintHTML(buf *bytes.Buffer)

func (*Task) PrintText

func (x *Task) PrintText(buf *bytes.Buffer)

type Text

type Text struct {
	Position
	Inline []Inline
	// contains filtered or unexported fields
}

func (*Text) PrintHTML

func (b *Text) PrintHTML(buf *bytes.Buffer)

type ThematicBreak

type ThematicBreak struct {
	Position
	// contains filtered or unexported fields
}

func (*ThematicBreak) PrintHTML

func (b *ThematicBreak) PrintHTML(buf *bytes.Buffer)

Directories

Path Synopsis
Mdfmt reformats Markdown data.
Mdfmt reformats Markdown data.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL