DocumentUtil

Description

static class Tinman.Core.Document.DocumentUtil

Helper class for dealing with text documents.

Content for text documents can be specified using a simple mini-HTML dialect, which is defined by the following Grammar:

document := preamble doctype '<document' '>' blocks? '</document' '>' | blocks? ;
inlines  := inline+ ;

blocks   := block block* ;
doctype  := '<!DOCTYPE' 'document' 'PUBLIC' '"-//TINMAN//TEXTDOC//EN"' '"http://dtd.tinman3d.com/TextDocument.dtd"' '>' ;
preamble := '<?xml' 'version' '=' '"1.0"' 'encoding' '=' '"utf-8"' '?>' ;

block    := comment* (p | ol | ul | cdata | h1 | h2 | hr) ;
li       := '<li' '>' block* '</li' '>' ;
ol       := '<ol' '>' li* '</ol' '>' ;
ul       := '<ul' '>' li* '</ul' '>' ;

h1       := '<h1' '>' inline* '</h1' '>' ;
h2       := '<h2' '>' inline* '</h2' '>' ;
p        := '<p' '>' inline* '</p' '>' | inline+ ;

inline   := comment* (img | br | b | c | i | u | a | text) ;

a        := '<a' (href | name) ('/>' | '>' text '</a>') ;
b        := '<b' '>' text '</b' '>' ;
c        := '<c' '>' text '</c' '>' ;
i        := '<i' '>' text '</i' '>' ;
img      := '<img' src ('border' '=' '"1"')? '/>' ;
u        := '<u' '>' text '</u' '>' ;

href     := 'href' '=' '"' (char-2 | entity)+ '"' ;
name     := 'name' '=' '"' (char-2 | entity)+ '"' ;
src      := 'src' '=' '"' (char-2 | entity)+ '"' ;
text     := (char-1 | entity)+ ;

br       := '<br' '/>' ;
cdata    := '<![CDATA[' ~']]>'* ']]>' ;
char-1   := ]<&[+ ;
char-2   := ]<"\r&\n[+ ;
comment  := '<!--' ~'-->'* '-->' ;
entity   := '&lt;' | '&amp;' | '&gt;' | '&quot;' | '&apos;' ;
hr       := '<hr' '/>' ;

Use the BlockContent and InlineContent methods to populate text document nodes with mini-HTML content:

Public / Methods

BlockContent


public static method BlockContent → (2)

content in : string

[not-null]
The mini-HTML content (see rule 'blocks').

output in : ICollector<IBlockNode>

[not-null]
The output document node.

Populates the given document node with block content.

ValidatingException

If one or more parsing errors have occurred.

EscapeMiniHtml


[Pure]
public static method EscapeMiniHtml → (2)

text in : string

The text to escape.

attribute opt : bool = false

Escape for attribute value?

returns → string

The escaped text.

Escapes the given text.

InlineContent


public static method InlineContent → (2)

content in : string

[not-null]
The mini-HTML content (see rule 'inlines').

output in : ICollector<IInlineNode>

[not-null]
The output document node.

Populates the given document node with block content.

ValidatingException

If one or more parsing errors have occurred.

MakeAnchorName


[Pure]
public static method MakeAnchorName → (1)

name in : string

[not-null]
The anchor name.

returns → string

The valid anchor name (see AnchorNode.Name).

Makes a valid anchor name for the given name in.

PlainText


[Pure]
public static method PlainText → (1)

node in : ContentNode<IInlineNode>

[not-null]
The document node.

returns → string

The extracted plain text content.

Extracts the plain text content (see ITextContentNode.Text) in the given node, adding whitespace characters where necessary (see ITextContentNode.Flags).