std/markdown/tree

std/markdown/src/tree.trb

The document tree of Markdown: blocks, which hold blocks or inlines, and inlines, which hold text. It is a value - built by the parser, read by the HTML renderer and the writer, and changed by a program like any other value.

type MarkdownDocument

type MarkdownDocument

A parsed Markdown document: its blocks, and the front matter it starts with, if any.

field blocks

blocks: List<MarkdownBlock>

The top-level blocks of the document, in order, without the front matter.

field frontMatter

frontMatter: FrontMatter? = None

The front matter, or None when the document has none or it was parsed without front matter.

type FrontMatter

type FrontMatter

The front matter of a document: the text between a first line --- and the next line --- or ..., which is YAML. line is the line of its first line of text, counted from 1.

field text

text: String

The YAML text between the delimiter lines, each line ending in a line break; empty for an empty front matter.

field line

line: Int

The line of the document, counted from 1, on which text starts; the parser sets it to 2.

fn document

fn document(): Result<YamlDocument, YamlError>

The front matter as a YAML document, whose lines count in the Markdown document.

type MarkdownBlock

type MarkdownBlock

One block, and the lines it spans, counted from 1.

field content

content: BlockContent

What the block is, with its content.

field line

line: Int = 0

The line on which the block starts, counted from 1 in the whole document; 0 for a block built by hand.

field endLine

endLine: Int = 0

The last line the block covers, counted like line; 0 for a block built by hand.

type BlockContent

type BlockContent

What a block is.

case Paragraph

case Paragraph(inlines: List<MarkdownInline>)

A paragraph and the inlines of its text.

case Heading

case Heading(level: Int, inlines: List<MarkdownInline>)

# Title or a line underlined with = or -; level is 1 to 6.

case ThematicBreak

case ThematicBreak

A thematic break, the horizontal rule of ---, *** or ___.

case CodeBlock

case CodeBlock(info: String, text: String, fenced: Bool)

A fenced block with its info string, or an indented one, whose info string is empty.

case HtmlBlock

case HtmlBlock(html: String)

A block of raw HTML, written through as it is, without its final line break.

case BlockQuote

case BlockQuote(blocks: List<MarkdownBlock>)

A block quote and the blocks inside it.

case ItemList

case ItemList(list: MarkdownList)

A bullet list or an ordered list.

case Table

case Table(table: MarkdownTable)

A table of GitHub Flavored Markdown.

type MarkdownList

type MarkdownList

A bullet list or an ordered list. marker is the bullet (-, +, *) or the delimiter after the number (., )); start is the first number of an ordered list. A list is tight when no blank line separates its items or the blocks inside them, and a tight list's paragraphs are written without <p>.

field ordered

ordered: Bool

Whether the list is numbered; otherwise it is a bullet list.

field marker

marker: String

The bullet of a bullet list, or the delimiter after the number of an ordered list.

field start

start: Int

The number of the first item of an ordered list; 1 for a bullet list.

field tight

tight: Bool

Whether no blank line separates the items or the blocks inside them.

field items

items: List<ListItem>

The items of the list, in order.

type ListItem

type ListItem

One item of a list: the blocks it holds, and the line of its marker.

field blocks

blocks: List<MarkdownBlock>

The blocks of the item, in order.

field line

line: Int = 0

The line of the item's marker, counted from 1 in the whole document; 0 for an item built by hand.

type ColumnAlignment

type ColumnAlignment

How a column of a table is aligned, as its delimiter row says.

case Unspecified

case Unspecified

A delimiter such as ---, with no colon.

case Left

case Left

A delimiter such as :--.

case Center

case Center

A delimiter such as :-:.

case Right

case Right

A delimiter such as --:.

type MarkdownTable

type MarkdownTable

A table: the alignment of each column, the cells of its header row, and the cells of each row after it.

field alignments

alignments: List<ColumnAlignment>

The alignment of each column, from the delimiter row.

field header

header: List<List<MarkdownInline>>

The cells of the header row, each cell as its inlines.

field rows

rows: List<List<List<MarkdownInline>>>

The body rows, each row a list of cells and each cell its inlines.

type MarkdownInline

type MarkdownInline

What a paragraph, a heading or a cell holds. line of a link or an image is the line it starts on.

case Text

case Text(text: String)

Plain text, with its escapes and entities already resolved.

case Code

case Code(text: String)

`code`: the text between the backticks.

case Emphasis

case Emphasis(children: List<Self>)

Emphasis, written *text* or _text_, and the inlines inside it.

case Strong

case Strong(children: List<Self>)

Strong emphasis, written **text** or __text__, and the inlines inside it.

case Image

case Image(destination: String, title: String, children: List<Self>, line: Int)

An image of destination with an optional title (empty if none); children are its description.

case Html

case Html(html: String)

Raw HTML, written through as it is.

case SoftBreak

case SoftBreak

A line break that is only a break of the source: rendered as a line break of the output, or a space.

case HardBreak

case HardBreak

A line break that is one: two spaces or a \ at the end of the line.

extend List<MarkdownInline>

extend List<MarkdownInline>

Adds plainText to a list of inlines, to read their text without the markup.

Examples

const emphasized = MarkdownInline.Emphasis([MarkdownInline.Text("world")])
const inlines = [MarkdownInline.Text("Hello "), emphasized]
print inlines.plainText()

fn plainText

fn plainText(): String

The text of the inlines without their markup: what an image's alt is, and what a heading's anchor is made of.