module watt.markdown.ast

Main importer for markdown parser.

Code Map

//! Main importer for markdown parser.
module watt.markdown.ast;


//! The type of node.
enum Type
{
	Document,
	BlockQuote,
	List,
	Item,
	CodeBlock,
	HtmlBlock,
	Paragraph,
	Heading,
	ThematicBreak,
	Text,
	Softbreak,
	Linebreak,
	Code,
	HtmlInline,
	Emph,
	Strong,
	Link,
	Image,
}

//! Base struct for all nodes.
class Node
{
public:
	type: Type;


public:
	this() { }
	fn toDocument() Document { }
	fn toBlockQuote() BlockQuote { }
	fn toList() List { }
	fn toItem() Item { }
	fn toCodeBlock() CodeBlock { }
	fn toHtmlBlock() HtmlBlock { }
	fn toParagraph() Paragraph { }
	fn toHeading() Heading { }
	fn toThematicBreak() ThematicBreak { }
	fn toText() Text { }
	fn toSoftbreak() Softbreak { }
	fn toLinebreak() Linebreak { }
	fn toCode() Code { }
	fn toHtmlInline() HtmlInline { }
	fn toEmph() Emph { }
	fn toStrong() Strong { }
	fn toLink() Link { }
	fn toImage() Image { }
	fn toParent() Parent { }
	fn toDocumentFast() Document { }
	fn toBlockQuoteFast() BlockQuote { }
	fn toListFast() List { }
	fn toItemFast() Item { }
	fn toCodeBlockFast() CodeBlock { }
	fn toHtmlBlockFast() HtmlBlock { }
	fn toParagraphFast() Paragraph { }
	fn toHeadingFast() Heading { }
	fn toThematicBreakFast() ThematicBreak { }
	fn toTextFast() Text { }
	fn toSoftbreakFast() Softbreak { }
	fn toLinebreakFast() Linebreak { }
	fn toCodeFast() Code { }
	fn toHtmlInlineFast() HtmlInline { }
	fn toEmphFast() Emph { }
	fn toStrongFast() Strong { }
	fn toLinkFast() Link { }
	fn toImageFast() Image { }
	fn toParentFast() Parent { }
}

//! A Parent node can have children nodes.
class Parent : Node
{
public:
	children: Node[];


public:
	this() { }
}

//! A Document node represents the entire markdown text.
class Document : Parent
{
public:
	this() { }
}

//! A Parent block from lines that start with >.
class BlockQuote : Parent
{
public:
	lastLineBlank: bool;


public:
	this() { }
}

//! A Parent block that lists its children, either ordered or unordered.
class List : Parent
{
public:
	enum Kind
	{
		Bullet,
		Ordered,
	}


public:
	alias Bullet = Kind.Bullet;
	alias Ordered = Kind.Ordered;


public:
	kind: Kind;
	isTight: bool;
	blankLinePending: bool;
	leadingWhitespace: size_t;
	empty: bool;
	delimiter: string;
	separator: char;
	start: i32;


public:
	this() { }
}

//! An element in a List.
class Item : Parent
{
public:
	childPoint: size_t;


public:
	this() { }
}

//! A Block that contains text that is to be displayed as-is in a
//! monospace font.
class CodeBlock : Node
{
public:
	str: string;
	info: string;
	fenceIndentation: size_t;


public:
	this() { }
}

//! A block of raw HTML.
class HtmlBlock : Node
{
public:
	enum Kind
	{
		Script,
		Comment,
		Question,
		Bang,
		CData,
		Normal,
		Other,
	}


public:
	str: string;
	kind: Kind;
	parent: Parent;


public:
	this() { }
}

//! A Paragraph is the simplest parent block, usually containing text.
class Paragraph : Parent
{
public:
	this() { }
}

//! Demarks a section with text in a special style. Can be generated in
//! multiple ways.
class Heading : Parent
{
public:
	level: u32;


public:
	this() { }
}

//! Breaks a document into sections. Rendered with an  node in HTML.
class ThematicBreak : Node
{
public:
	this() { }
}

//! A written method of human communication.
class Text : Node
{
public:
	str: string;
	leadingWhitespace: size_t;
	slashToBreak: bool;
	run: string;


public:
	this() { }
}

//! A newline.
class Softbreak : Node
{
public:
	this() { }
}

//! Harder form of break than Softbreak, rendered with 
in HTML.
class Linebreak : Node { public: slashBreak: bool; public: this() { } } //! Like CodeBlock but inline. class Code : Node { public: str: string; public: this() { } } //! An inline HTML tag. class HtmlInline : Node { public: str: string; public: this() { } } //! First level of text emphasis. Rendered as italics. class Emph : Parent { public: this() { } } //! Second level of text emphasis. Rendered as bold. class Strong : Parent { public: this() { } } //! A Link to a URL. class Link : Parent { public: url: string; title: string; fromHtml: bool; public: this() { } } //! A Link to an image, intended for inline display. class Image : Parent { public: url: string; alt: string; title: string; public: this() { } } //! Visitor base class. class Visitor { public: this() { } fn enter(n: Document, sink: scope (Sink)) { } fn leave(n: Document, sink: scope (Sink)) { } fn enter(n: BlockQuote, sink: scope (Sink)) { } fn leave(n: BlockQuote, sink: scope (Sink)) { } fn enter(n: List, sink: scope (Sink)) { } fn leave(n: List, sink: scope (Sink)) { } fn enter(n: Item, sink: scope (Sink)) { } fn leave(n: Item, sink: scope (Sink)) { } fn enter(n: Paragraph, sink: scope (Sink)) { } fn leave(n: Paragraph, sink: scope (Sink)) { } fn enter(n: Heading, sink: scope (Sink)) { } fn leave(n: Heading, sink: scope (Sink)) { } fn enter(n: Emph, sink: scope (Sink)) { } fn leave(n: Emph, sink: scope (Sink)) { } fn enter(n: Link, sink: scope (Sink)) { } fn leave(n: Link, sink: scope (Sink)) { } fn enter(n: Image, sink: scope (Sink)) { } fn leave(n: Image, sink: scope (Sink)) { } fn enter(n: Strong, sink: scope (Sink)) { } fn leave(n: Strong, sink: scope (Sink)) { } fn visit(n: HtmlBlock, sink: scope (Sink)) { } fn visit(n: CodeBlock, sink: scope (Sink)) { } fn visit(n: ThematicBreak, sink: scope (Sink)) { } fn visit(n: Text, sink: scope (Sink)) { } fn visit(n: Softbreak, sink: scope (Sink)) { } fn visit(n: Linebreak, sink: scope (Sink)) { } fn visit(n: Code, sink: scope (Sink)) { } fn visit(n: HtmlInline, sink: scope (Sink)) { } } //! Dispatch to correct visitor function. fn accept(n: Node, v: Visitor, sink: scope (Sink)) { }
enum Type

The type of node.

class Node

Base struct for all nodes.

class Parent : Node

A Parent node can have children nodes.

class Document : Parent

A Document node represents the entire markdown text.

class BlockQuote : Parent

A Parent block from lines that start with >.

class List : Parent

A Parent block that lists its children, either ordered or unordered.

class Item : Parent

An element in a List.

class CodeBlock : Node

A Block that contains text that is to be displayed as-is in a monospace font.

class HtmlBlock : Node

A block of raw HTML.

class Paragraph : Parent

A Paragraph is the simplest parent block, usually containing text.

class Heading : Parent

Demarks a section with text in a special style. Can be generated in multiple ways.

class ThematicBreak : Node

Breaks a document into sections. Rendered with an


node in HTML.

class Text : Node

A written method of human communication.

The first instances are recorded at about 6000 BC.

Bugs

  • Tone is often hard to convey, meaning discussions can be more difficult than face-to-face.
class Softbreak : Node

A newline.

class Linebreak : Node

Harder form of break than Softbreak, rendered with <br> in HTML.

class Code : Node

Like CodeBlock but inline.

class HtmlInline : Node

An inline HTML tag.

class Emph : Parent

First level of text emphasis. Rendered as italics.

class Strong : Parent

Second level of text emphasis. Rendered as bold.

class Link : Parent

A Link to a URL.

class Image : Parent

A Link to an image, intended for inline display.

class Visitor

Visitor base class.

fn accept(n: Node, v: Visitor, sink: scope (Sink))

Dispatch to correct visitor function.