Documentation
¶
Index ¶
- func Entity(s string) (n int, text string)
- func NormalizeLabel(s string) string
- func PlainText(in []Inline) string
- type Align
- type Block
- type Document
- func (d *Document) Append(text string)
- func (d *Document) Block(i int) *Block
- func (d *Document) Children(i int) iter.Seq[int]
- func (d *Document) Edit(from, to int, text string)
- func (d *Document) Extensions() Extensions
- func (d *Document) Footnote(label string) (int, bool)
- func (d *Document) HTML() string
- func (d *Document) Inlines(i int) []Inline
- func (d *Document) Len() int
- func (d *Document) Line(i, k int) (string, int)
- func (d *Document) LineCount(i int) int
- func (d *Document) Lines(i int) string
- func (d *Document) Set(src string)
- func (d *Document) SetStreaming(on bool)
- func (d *Document) Source() string
- func (d *Document) Streaming() bool
- func (d *Document) String() string
- type Extensions
- type Inline
- type InlineKind
- type Kind
- type Task
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Entity ¶
Entity reads the entity or numeric character reference s starts with, as & or #, returning its length and the text it stands for, or 0 when s starts with none that Markdown reads.
func NormalizeLabel ¶
NormalizeLabel normalizes a label as CommonMark matches link references and footnotes: whitespace collapsed and case folded.
Types ¶
type Block ¶
type Block struct {
Kind Kind
// Parent is the index of the block holding it, -1 for the root.
Parent int
// Next is the index after the block and its descendants.
Next int
// Start and End are the offsets of the block's bytes in the source,
// from its first character to the end of its last line.
Start, End int
// Open reports that the block is still open at the end of the
// source, so that more text can continue it: a fence without its
// closing fence, or the paragraph being written.
Open bool
// Level is a heading's, from 1 to 6.
Level int
// Ordered, Number (an ordered list's first), Marker (*, - or + for
// a bullet list, . or ) after an ordered list's numbers) and Tight
// (no blank lines between its items and their blocks) describe a
// list.
Ordered bool
Number int
Marker byte
Tight bool
// Task is an item's check box.
Task Task
// Fenced tells a fenced code block from an indented one.
Fenced bool
// Header tells a table's header row.
Header bool
// Align is the alignment of a table's columns.
Align []Align
// contains filtered or unexported fields
}
Block is a block of a document: blocks are in document order, a block's children right after it, up to its Next.
func (*Block) Healed ¶
Healed reports whether the block's inlines were completed as the tail of a streaming document: their closers are not in the source, and change as it grows.
func (*Block) Info ¶
Info returns a fenced code block's info string, unescaped, its language first (see Language).
type Document ¶
type Document struct {
// contains filtered or unexported fields
}
Document is Markdown parsed, which takes text appended to it, or edits, and parses only what they change.
func (*Document) Append ¶
Append adds text to the end of the document, parsing again only the outermost block still open before it, or nothing but the new lines when no block is.
func (*Document) Block ¶
Block returns block i, 0 being the root. The block stays valid until the document changes.
func (*Document) Edit ¶
Edit replaces the source's bytes [from, to) with text. Parsing restarts at the top-level block before the change and goes on until a top-level block starts where one started before it, from which the blocks parsed before are kept.
func (*Document) Extensions ¶
func (d *Document) Extensions() Extensions
Extensions returns what the document reads beyond CommonMark.
func (*Document) Footnote ¶
Footnote returns the FootnoteDefinition block of a label, as a FootnoteRef's Text holds it.
func (*Document) HTML ¶
HTML returns the document as HTML, as cmark-gfm renders it, raw HTML included as written.
func (*Document) Inlines ¶
Inlines returns the inlines of block i, a paragraph, a heading or a table cell, parsing them the first time.
func (*Document) Line ¶
Line returns line k of a code, HTML or math block, without its newline, and the offset in the source of its first byte.
func (*Document) Lines ¶
Lines returns the content of a code, HTML or math block, each line ending with a newline.
func (*Document) Set ¶
Set makes src the text of the document, parsing only what changed since the last: text appended to it, or else the blocks around the change (see Edit).
func (*Document) SetStreaming ¶
SetStreaming sets whether the document is text still being written, as a language model's reply: its end then shows what it will most likely become rather than the half-written syntax it is. The last paragraph closes its emphasis, code spans, strikethrough and math, a link whose destination is being written is a link (Inline.Pending), a tag being written is left out, and lines that could still turn into something else are held back: a line of only a few markers, as - or ==, which would make the paragraph above a heading, and a table's header until its delimiter row comes. Finished blocks are never changed. Turn it off once the text is complete, to parse its end exactly as CommonMark does.
type Extensions ¶
type Extensions uint32
Extensions are the syntax a Document reads beyond CommonMark.
const ( // ExtTables are GitHub's tables, of cells between pipes. ExtTables Extensions = 1 << iota // ExtTaskLists are list items starting with [ ] or [x]. ExtTaskLists // ExtStrikethrough is text between one or two tildes. ExtStrikethrough // ExtAutolinks are links without angle brackets: www.example.com, // https://example.com and someone@example.com. ExtAutolinks // ExtFootnotes are references as [^1], defined by [^1]: lines. ExtFootnotes // ExtMath is TeX between $$ and $$, \[ and \], or \( and \), in blocks // of their own or within text. ExtMath // ExtDollarMath is TeX between single dollar signs, as $x^2$, except // where the dollars read as amounts of money: not after an opening // dollar followed by a space or a digit, nor before a closing one // following a space or followed by a digit. It needs ExtMath. ExtDollarMath // GFM is GitHub Flavored Markdown. GFM = ExtTables | ExtTaskLists | ExtStrikethrough | ExtAutolinks // Default is GitHub Flavored Markdown with footnotes and math, as // language models write it. Default = GFM | ExtFootnotes | ExtMath )
type Inline ¶
type Inline struct {
Kind InlineKind
// Text is the literal of Text, Code, HTML and Math, and the label of
// a FootnoteRef.
Text string
// Dest and Title are a link's or an image's.
Dest, Title string
// Start and End are the offsets of the inline's bytes in the source.
Start, End int
// Next is the index after the inline and its children.
Next int
// Auto tells a link written as its address, as <https://…> or
// www.example.com.
Auto bool
// Display tells math shown on its own lines, between $$ or \[ \].
Display bool
// Pending tells, while the document is streaming, a link or an image
// whose destination is still being written.
Pending bool
}
Inline is an inline of a block's content: inlines are in document order, an inline's children right after it, up to its Next.
type InlineKind ¶
type InlineKind uint8
InlineKind is what an inline is.
const ( // Text is literal text, in Text. Text InlineKind = iota // SoftBreak is a line ending within a paragraph, shown as a space. SoftBreak // LineBreak is a hard line break. LineBreak // Code is a code span, its text in Text. Code Emphasis Strong Strikethrough // Link holds the inlines of its text, to Dest, titled Title. Link // Image holds the inlines of its description, from Dest. Image // HTML is raw HTML, in Text. HTML // Math is TeX, in Text, Display or within the line. Math // FootnoteRef refers to the footnote labelled Text. FootnoteRef )
Kinds of inlines.
func (InlineKind) String ¶
func (k InlineKind) String() string
type Kind ¶
type Kind uint8
Kind is what a block is.
const ( // Root holds the top-level blocks: block 0 of a document. Root Kind = iota Paragraph // Heading has a Level from 1 to 6. Heading ThematicBreak // CodeBlock is fenced or indented code, whose Info string names the // language of a fence. CodeBlock // HTMLBlock is raw HTML, whose lines are its content. HTMLBlock // Quote is a block quote, holding blocks. Quote // List holds items, Ordered or not, Tight or not. List // Item is an item of a list, holding blocks, with a Task state. Item // Table holds rows, the first its Header, whose cells align as Align // says. Table TableRow // TableCell holds inline content. TableCell // FootnoteDefinition holds the blocks of a footnote, its Label the // footnote's. FootnoteDefinition // MathBlock is display math, whose lines are its TeX. MathBlock )
Kinds of blocks.