module watt.markdown.util

Utils for markdown AST.

Code Map

//! Utils for markdown AST.
module watt.markdown.util;


enum CODE_INDENT;

//! State for email validator.
enum EmailState
{
	BeforeAt,
	DomainStart,
	DomainBody,
}

//! Create a Document node and return it.
fn buildDocument() Document { }
//! Create a BlockQuote node, add it to children and return it.
fn addBlockQuote(children: Node[]) BlockQuote { }
//! Create a List node, add it to children and return it.
fn addList(children: Node[]) List { }
//! Create a Item node, add it to children and return it.
fn addItem(children: Node[]) Item { }
//! Create a CodeBlock node, add it to children and return it.
fn addCodeBlock(children: Node[], str: string, info: string) CodeBlock { }
//! Create a HtmlBlock node, add it to children and return it.
fn addHtmlBlock(children: Node[], str: string) HtmlBlock { }
//! Create an HtmlBlock node.
fn buildHtmlBlock() HtmlBlock { }
//! Create a Paragraph node, add it to children and return it.
fn addParagraph(children: Node[]) Paragraph { }
//! Create a Paragraph node, don't add it anywhere.
fn buildParagraph() Paragraph { }
//! Create a Heading node, add it to children and return it.
fn addHeading(children: Node[], level: u32) Heading { }
//! Create a Heading node, don't add it anywhere.
fn buildHeading(level: u32) Heading { }
//! Create a ThematicBreak node, add it to children and return it.
fn addThematicBreak(children: Node[]) ThematicBreak { }
//! Create a Text node, add it to children and return it.
fn addText(children: Node[], str: string) Text { }
//! Create a Text node, don't add it anywhere.
fn buildText(str: string) Text { }
//! Create a Softbreak node, add it to children and return it.
fn addSoftbreak(children: Node[]) Softbreak { }
//! Create a Linebreak node, add it to children and return it.
fn addLinebreak(children: Node[]) Linebreak { }
//! Create a Code node, add it to children and return it.
fn addCode(children: Node[], str: string) Code { }
//! Create a Code node.
fn buildCode(str: string) Code { }
//! Create an HtmlInline node, add it to children and return it.
fn addHtmlInline(children: Node[], str: string) HtmlInline { }
//! Build an HtmlInline node.
fn buildHtmlInline(str: string) HtmlInline { }
//! Create a Emph node, add it to children and return it.
fn addEmph(children: Node[]) Emph { }
//! Create a Emph node, don't add it anywhere.
fn buildEmph() Emph { }
//! Create a Strong node, don't add it anywhere.
fn buildStrong() Strong { }
//! Create a Strong node, add it to children and return it.
fn addStrong(children: Node[]) Strong { }
//! Create a Link node, add it to children and return it.
fn addLink(children: Node[], url: string, title: string) Link { }
//! Create a Link node.
fn buildLink() Link { }
//! Create a Link node.
fn buildLink(url: string, title: string) Link { }
//! Create a Image node, add it to children and return it.
fn addImage(children: Node[], url: string, title: string) Image { }
//! Build an Image node.
fn buildImage(url: string, alt: string, title: string) Image { }
//! Consume characters until a character is found.
fn consumeUntilChar(str: string, outStr: string, c: char) bool { }
//! Consume a link tag.
fn consumeTag(str: string, tag: string) bool { }
//! Consume one character.
fn consumeChar(str: string, c: char) bool { }
//! Consume whitespace.
fn consumeWhitespace(str: string) { }
//! Consume a URL.
fn consumeUrl(str: string, url: string) bool { }
//! Count the whitespace at the beginning of a string.
fn countLeadingWhitespace(str: string) size_t { }
//! Starting from i, count how much whitespace until the first
//! nonwhitespace character. If as much or more whitespace than maxLength
//! is counted, return immediately. Tabs count as 4.
fn countContiguousWhitespace(str: string, maxLength: size_t, i: size_t) size_t { }
//! Remove a delimiter length worth of characters from the front of str.
//! Taking into account tabs etc.
fn removeDelimiter(str: string, delimiter: size_t, forceFourTab: bool) string { }
//! Create a string filled with spaces len characters long.
fn emptyString(len: size_t) string { }
//! Create a string len characters long, filled with c characters.
fn uniformString(len: size_t, c: char) string { }
//! Get the string representation of a paragraph.
fn paragraphToString(p: Paragraph) string { }
fn markdownPunctuation(c: dchar) bool { }
//! Turn consecutive whitespace into a single whitespace.
fn collapseWhitespace(str: string) string { }
//! Escape a string using markdown escape rules.
fn markdownEscape(str: string) string { }
//! Build an AutoLink node.
fn makeAutoLink(url: string) Node { }
//! Build an EmailLink node.
fn makeEmailLink(url: string) Node { }
//! Build an AutoLinkNode.
fn makeStandaloneAutoLink(url: string) Node { }
fn isAbsoluteURI(str: string) bool { }
//! Percent encode a given url string. This isn't quite 'standard' in a few
//! ways:
fn urlEscape(str: string) string { }
//! Escape HTML entities.
fn htmlEntityEscape(str: string) string { }
fn isEmailAddress(str: string) bool { }
//! Is the string valid to be an HTML block?
fn validBlockHtml(str: string) bool { }
fn validInlineHtml(str: string) bool { }
//! Strip characters from a string hat are not allowed in image link
//! titles.
fn altStringPresentation(str: string) string { }
//! Replace an HTML entity with the correct unicode character.
fn replaceEntity(str: string) string { }
fn buildDocument() Document

Create a Document node and return it.

fn addBlockQuote(children: Node[]) BlockQuote

Create a BlockQuote node, add it to children and return it.

fn addList(children: Node[]) List

Create a List node, add it to children and return it.

fn addItem(children: Node[]) Item

Create a Item node, add it to children and return it.

fn addCodeBlock(children: Node[], str: string, info: string) CodeBlock

Create a CodeBlock node, add it to children and return it.

fn addHtmlBlock(children: Node[], str: string) HtmlBlock

Create a HtmlBlock node, add it to children and return it.

fn buildHtmlBlock() HtmlBlock

Create an HtmlBlock node.

fn addParagraph(children: Node[]) Paragraph

Create a Paragraph node, add it to children and return it.

fn buildParagraph() Paragraph

Create a Paragraph node, don't add it anywhere.

fn addHeading(children: Node[], level: u32) Heading

Create a Heading node, add it to children and return it.

fn buildHeading(level: u32) Heading

Create a Heading node, don't add it anywhere.

fn addThematicBreak(children: Node[]) ThematicBreak

Create a ThematicBreak node, add it to children and return it.

fn addText(children: Node[], str: string) Text

Create a Text node, add it to children and return it.

fn buildText(str: string) Text

Create a Text node, don't add it anywhere.

fn addSoftbreak(children: Node[]) Softbreak

Create a Softbreak node, add it to children and return it.

fn addLinebreak(children: Node[]) Linebreak

Create a Linebreak node, add it to children and return it.

fn addCode(children: Node[], str: string) Code

Create a Code node, add it to children and return it.

fn buildCode(str: string) Code

Create a Code node.

fn addHtmlInline(children: Node[], str: string) HtmlInline

Create an HtmlInline node, add it to children and return it.

fn buildHtmlInline(str: string) HtmlInline

Build an HtmlInline node.

fn addEmph(children: Node[]) Emph

Create a Emph node, add it to children and return it.

fn buildEmph() Emph

Create a Emph node, don't add it anywhere.

fn buildStrong() Strong

Create a Strong node, don't add it anywhere.

fn addStrong(children: Node[]) Strong

Create a Strong node, add it to children and return it.

fn addLink(children: Node[], url: string, title: string) Link

Create a Link node, add it to children and return it.

fn buildLink() Link

Create a Link node.

fn addImage(children: Node[], url: string, title: string) Image

Create a Image node, add it to children and return it.

fn buildImage(url: string, alt: string, title: string) Image

Build an Image node.

fn consumeUntilChar(str: string, outStr: string, c: char) bool

Consume characters until a character is found.

fn consumeTag(str: string, tag: string) bool

Consume a link tag.

fn consumeChar(str: string, c: char) bool

Consume one character.

fn consumeWhitespace(str: string)

Consume whitespace.

fn consumeUrl(str: string, url: string) bool

Consume a URL.

fn countLeadingWhitespace(str: string) size_t

Count the whitespace at the beginning of a string.

fn countContiguousWhitespace(str: string, maxLength: size_t, i: size_t) size_t

Starting from i, count how much whitespace until the first nonwhitespace character. If as much or more whitespace than maxLength is counted, return immediately. Tabs count as 4.

fn removeDelimiter(str: string, delimiter: size_t, forceFourTab: bool) string

Remove a delimiter length worth of characters from the front of str. Taking into account tabs etc.

fn emptyString(len: size_t) string

Create a string filled with spaces len characters long.

fn uniformString(len: size_t, c: char) string

Create a string len characters long, filled with c characters.

fn paragraphToString(p: Paragraph) string

Get the string representation of a paragraph.

fn markdownPunctuation(c: dchar) bool

Return

true if c is markdown punctuation.

fn collapseWhitespace(str: string) string

Turn consecutive whitespace into a single whitespace.

fn markdownEscape(str: string) string

Escape a string using markdown escape rules.

fn makeAutoLink(url: string) Node

Build an AutoLink node.

fn makeEmailLink(url: string) Node

Build an EmailLink node.

fn makeStandaloneAutoLink(url: string) Node

Build an AutoLinkNode.

fn isAbsoluteURI(str: string) bool

Return

true if str is an absolute URI, according to markdown rules.

fn urlEscape(str: string) string

Percent encode a given url string. This isn't quite 'standard' in a few ways:

  • % is never encoded. The test suite has a nasty habit of passing a half encoded URL, saying 'the spec doesn't actually care', but expecting it one way, so we don't encode it as %25.
  • [] are encoded. The RFC for this stuff states that the brackets are permissible, and do not need to be encoded, but CommonMark expects them to be.
fn htmlEntityEscape(str: string) string

Escape HTML entities.

enum EmailState

State for email validator.

fn isEmailAddress(str: string) bool

Return

true if str could be an email address.

fn validBlockHtml(str: string) bool

Is the string valid to be an HTML block?

This is all a bit hacky, but a full HTML parser seems out of scope. Basically these characters could be in a string or something, but if there's not been whitespace, there's no way they could be valid.

fn validInlineHtml(str: string) bool

Return

true if str is valid inline HTML.

fn altStringPresentation(str: string) string

Strip characters from a string hat are not allowed in image link titles.

fn replaceEntity(str: string) string

Replace an HTML entity with the correct unicode character.