Documentation
¶
Overview ¶
Package markdown provides a parser for converting Markdown text into an AST. It uses the tokenizer package to scan input and builds a tree of nodes representing the document structure.
Supported Syntax ¶
Currently supported Markdown elements:
- Headings: # H1, ## H2, ### H3, etc.
- Blockquotes: > quoted text
- Paragraphs: Separated by blank lines
- Tables: | head | head | pipe-style tables with optional header rows
- Unordered lists: - item, * item, or + item
- Ordered lists: 1. item or 1) item
- Emphasis: _italic_ or *italic*
- Strong: __bold__ or **bold**
- Strikethrough: ~~deleted~~
- Code: `code` using backticks
- Fenced code blocks: ```language ... ```
- Horizontal rules: ---
- Links: [text](url) or <url>
- Images: 
Example ¶
doc := markdown.Parse(strings.NewReader("# Hello _world_"), tokenizer.Pos{})
fmt.Println(doc) // <doc><h1>Hello <em>world</em></h1></doc>
Index ¶
- func Parse(r io.Reader, pos tokenizer.Pos) ast.Node
- type Blockquote
- type Code
- type CodeBlock
- type Document
- type Emphasis
- type Heading
- type Image
- type Link
- type List
- type ListItem
- type Paragraph
- type Rule
- type Strikethrough
- type Strong
- type Table
- type TableCell
- type TableHeader
- type TableRow
- type Text
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Blockquote ¶
type Blockquote struct {
// contains filtered or unexported fields
}
Blockquote represents a blockquote element in Markdown (> quoted text). It can contain paragraphs and other block elements.
func NewBlockquote ¶
func NewBlockquote() *Blockquote
NewBlockquote creates a new empty Blockquote node.
func (*Blockquote) Append ¶
func (b *Blockquote) Append(child ast.Node)
Append adds a child node to this blockquote.
func (*Blockquote) Children ¶
func (b *Blockquote) Children() []ast.Node
Children returns the child nodes contained within this blockquote.
func (*Blockquote) Kind ¶
func (b *Blockquote) Kind() ast.Kind
Kind returns the AST node kind for this blockquote.
func (*Blockquote) String ¶
func (b *Blockquote) String() string
String returns an HTML representation of the blockquote.
type Code ¶
type Code struct {
// contains filtered or unexported fields
}
Code is an inline node for code spans. In Markdown, inline code is created with backticks: `code` Code nodes are leaf nodes that contain the literal code text.
func NewCode ¶
NewCode creates a new code node with the given content. The value represents the code text without the surrounding backticks.
type CodeBlock ¶
type CodeBlock struct {
// contains filtered or unexported fields
}
CodeBlock is a block node for fenced code blocks. In Markdown, fenced code blocks are created with triple backticks: ```language code here ``` The language is optional and specifies syntax highlighting.
func NewCodeBlock ¶
NewCodeBlock creates a new code block node with the given language and content. The language may be empty if not specified.
type Document ¶
type Document struct {
// contains filtered or unexported fields
}
Document is the root node of a Markdown AST. It contains all block-level elements (paragraphs, headings, etc.) as children.
func NewDocument ¶
func NewDocument() *Document
NewDocument creates a new empty document node. Use Append() to add child nodes such as paragraphs.
type Emphasis ¶
type Emphasis struct {
// contains filtered or unexported fields
}
Emphasis is an inline node for emphasized (italic) text. In Markdown, emphasis is created with single underscores: _italic_ The emphasis node contains child nodes representing the emphasized content.
func NewEmphasis ¶
func NewEmphasis() *Emphasis
NewEmphasis creates a new empty emphasis node. Use Append() to add the content that should be emphasized.
type Heading ¶
type Heading struct {
// contains filtered or unexported fields
}
Heading is a block-level node for headings (h1-h6). In Markdown, headings are created with hash symbols: # H1, ## H2, etc. The level indicates the heading depth (1-6).
func NewHeading ¶
NewHeading creates a new heading node with the specified level (1-6). Use Append() to add the heading content.
type Image ¶
type Image struct {
// contains filtered or unexported fields
}
Image represents an image in Markdown ().
type Link ¶
type Link struct {
// contains filtered or unexported fields
}
Link represents a hyperlink in Markdown ([text](url)).
type List ¶
type List struct {
// contains filtered or unexported fields
}
List is a block-level node for both ordered and unordered lists. In Markdown, unordered lists are created with dashes, asterisks, or plus signs: - item 1 - item 2 Ordered lists are created with numbers followed by a period or parenthesis: 1. item 1 2. item 2 The list contains ListItem children.
func NewList ¶
func NewList() *List
NewList creates a new empty unordered list node. Use Append() to add ListItem children.
func NewOrderedList ¶
func NewOrderedList() *List
NewOrderedList creates a new empty ordered list node. Use Append() to add ListItem children.
type ListItem ¶
type ListItem struct {
// contains filtered or unexported fields
}
ListItem is a block-level node representing a single item in a list. In Markdown, list items start with a marker (-, *, +) followed by content. List items can contain inline formatting like emphasis, strong, code, etc.
func NewListItem ¶
func NewListItem() *ListItem
NewListItem creates a new empty list item node. Use Append() to add the item content.
type Paragraph ¶
type Paragraph struct {
// contains filtered or unexported fields
}
Paragraph is a block-level node containing inline content. Paragraphs are separated by blank lines in Markdown source. They can contain text, emphasis, strong, code, and other inline elements.
func NewParagraph ¶
func NewParagraph() *Paragraph
NewParagraph creates a new empty paragraph node. Use Append() to add inline content such as text or emphasis.
type Rule ¶
type Rule struct{}
Rule represents a horizontal rule in Markdown (---, ***, or ___).
type Strikethrough ¶
type Strikethrough struct {
// contains filtered or unexported fields
}
Strikethrough represents strikethrough text in Markdown (~~deleted~~).
func NewStrikethrough ¶
func NewStrikethrough() *Strikethrough
NewStrikethrough creates a new empty Strikethrough node.
func (*Strikethrough) Append ¶
func (s *Strikethrough) Append(child ast.Node)
Append adds a child node to this strikethrough.
func (*Strikethrough) Children ¶
func (s *Strikethrough) Children() []ast.Node
Children returns the child nodes contained within this strikethrough.
func (*Strikethrough) Kind ¶
func (s *Strikethrough) Kind() ast.Kind
Kind returns the AST node kind for this strikethrough.
func (*Strikethrough) String ¶
func (s *Strikethrough) String() string
String returns an HTML representation of the strikethrough.
type Strong ¶
type Strong struct {
// contains filtered or unexported fields
}
Strong is an inline node for strongly emphasized (bold) text. In Markdown, strong emphasis is created with double underscores: __bold__ The strong node contains child nodes representing the bold content.
func NewStrong ¶
func NewStrong() *Strong
NewStrong creates a new empty strong node. Use Append() to add the content that should be bold.
type Table ¶ added in v0.0.2
type Table struct {
// contains filtered or unexported fields
}
Table is a block-level node containing an optional header and zero or more rows.
func (*Table) Header ¶ added in v0.0.2
func (t *Table) Header() *TableHeader
func (*Table) SetHeader ¶ added in v0.0.2
func (t *Table) SetHeader(header *TableHeader)
type TableCell ¶ added in v0.0.2
type TableCell struct {
// contains filtered or unexported fields
}
TableCell represents a single table cell containing inline nodes.
func NewTableCell ¶ added in v0.0.2
func NewTableCell() *TableCell
type TableHeader ¶ added in v0.0.2
type TableHeader struct {
// contains filtered or unexported fields
}
TableHeader represents the header row of a table.
func NewTableHeader ¶ added in v0.0.2
func NewTableHeader() *TableHeader
func NewTableHeaderFromRow ¶ added in v0.0.2
func NewTableHeaderFromRow(row *TableRow) *TableHeader
func (*TableHeader) Append ¶ added in v0.0.2
func (h *TableHeader) Append(node ast.Node)
func (*TableHeader) Children ¶ added in v0.0.2
func (h *TableHeader) Children() []ast.Node
func (*TableHeader) Kind ¶ added in v0.0.2
func (h *TableHeader) Kind() ast.Kind
func (*TableHeader) String ¶ added in v0.0.2
func (h *TableHeader) String() string
type TableRow ¶ added in v0.0.2
type TableRow struct {
// contains filtered or unexported fields
}
TableRow represents a body row in a table.
func NewTableRow ¶ added in v0.0.2
func NewTableRow() *TableRow
type Text ¶
type Text struct {
// contains filtered or unexported fields
}
Text is an inline leaf node containing plain text content. Text nodes have no children and represent literal text in the document.
func NewText ¶
NewText creates a new text node with the given content. The value is stored as-is without any processing.