PeachBrackets
PeachBrackets.Building
DocumentNode Class
One box of a document built in code: an element, a run of text, an image or a list marker, with the style set on it.
public sealed class DocumentNode : System.IEquatable<PeachBrackets.Building.DocumentNode>
Inheritance System.Object → DocumentNode
Implements System.IEquatable<DocumentNode>
Remarks
The tree is what CreateAsync(DeclarativePage, HtmlDocumentOptions, StyleSheet) lays out, so a node behaves like the box a parsed element would become: SetStyle(string, string) takes a CSS property by name and a CSS value, the way a style attribute would. A node belongs to the DocumentBuildContext that made it. A node is a thin handle: two handles to the same box are equal.
| Properties | |
|---|---|
| Children | The node’s children, in order. |
| HasChildren | Whether the node has children of its own. |
| IsTableCell | Whether the node is laid out as a table cell. |
| Parent | The node this one is a child of, or null for a root. |
| PendingAutoDirection | Whether the node’s text direction is still to be worked out from its content once the content is complete (dir=auto semantics). CreateAsync(DeclarativePage, HtmlDocumentOptions, StyleSheet) resolves every node that is waiting. |
| RenderContext | The render context the node’s styles are resolved against. |
| SectionBeginId | The section a page-number counter inside this node counts within, set by BeginPageNumberOfSection-style builders: this node is where the section starts. Null for none. |
| SectionEndId | The section that ends at this node, or null for none; the counterpart of SectionBeginId. |
| TagName | The name of the element the node stands for (div, td, a), or null for a node that is not an element. |
| Text | The text the node holds, or null. A node holds text or children, never both. |
| Methods | |
|---|---|
| AddClass(string) | Adds a class to the element’s class attribute, making the node an element if it was not one. |
| AppendBlock() | Adds a plain block-level child, the building block of most structure. It inherits the node’s text styles. |
| AppendElement(string, IReadOnlyDictionary<string,string>) | Adds a child element. |
| AppendHtmlFragment(string, StyleSheet, Func<HtmlFragmentSlot,DocumentNode,bool>) | Parses an HTML fragment and puts what it makes inside a new block child, styled by styleSheet and the fragment’s own <style> elements. A <slot> element in the fragment is a hole the caller fills. |
| AppendImage(IReadOnlyDictionary<string,string>) | Adds an img child, which inherits the node’s text styles. Give it a picture with one of the Set...Content methods or a src attribute. |
| AppendListItem() | Adds a list item child, with its marker already in front: the child lays out as display: list-item. |
| AppendText(string) | Adds a child that is a text node with the given text. |
| GetAttribute(string) | Returns the value of an attribute of the element, or null if it has none by that name. |
| SetAttribute(string, string) | Sets an attribute of the element, making the node an element (a div) if it was not one. |
| SetBookmark(string, int) | Gives the node an outline entry (a bookmark) at the given level, labelled with title. |
| SetImageContent(SvgImage) | Gives an image node a vector picture. |
| SetImageContent(Image) | Gives an image node a decoded raster picture. |
| SetImageContent(Func<Size,byte[]>) | Gives an image node a raster picture made when its size is known: generator is called with the size, in points, the node ends up at, and returns the encoded image. |
| SetSectionPageCounter(string, bool) | Makes the node a page counter within a section: its text is the page number inside the section (or the section’s total page count, if isTotal is set), counted between the nodes marked with SectionBeginId and SectionEndId. |
| SetStyle(string, string) | Sets a CSS property on the node, as a style declaration would. |
| SetSvgContent(Func<Size,string>) | Gives an image node a vector picture made when its size is known: generator is called with the size, in points, the node ends up at, and returns SVG markup. |
| SetTagName(string) | Renames the element, making the node an element if it was not one. Selectors and the default styles see the new name. |
| SetTextAlign(string) | Sets how the node’s text is aligned, both on its lines and on its last line. |