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)) { }
The type of node.
Base struct for all nodes.
A Parent node can have children nodes.
A Document node represents the entire markdown text.
A Parent block from lines that start with >
.
A Parent block that lists its children, either ordered or unordered.
An element in a List.
A Block that contains text that is to be displayed as-is in a monospace font.
A block of raw HTML.
A Paragraph is the simplest parent block, usually containing text.
Demarks a section with text in a special style. Can be generated in multiple ways.
Breaks a document into sections. Rendered with an
node in HTML.
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.
A newline.
Harder form of break than Softbreak, rendered with <br>
in HTML.
Like CodeBlock but inline.
An inline HTML tag.
First level of text emphasis. Rendered as italics.
Second level of text emphasis. Rendered as bold.
A Link to a URL.
A Link to an image, intended for inline display.
Visitor base class.
Dispatch to correct visitor function.