HtmlMarkupWriter Class
Writes the markup of a node. The default implementation is the HTML fragment serialization algorithm (https://html.spec.whatwg.org/multipage/parsing.html#serialising-html-fragments); a derived class customizes the output by overriding the method of each kind of node.
public class HtmlMarkupWriterRemarks
The tree is walked iteratively, so deep trees do not overflow the stack. An instance writes one node: create a new writer for each call (see HtmlFormatter.CreateWriter).
Constructors
| Name | Description |
|---|---|
| HtmlMarkupWriter(TextWriter) | Creates a writer that emits HTML markup to the given output. |
HtmlMarkupWriter(TextWriter)
HtmlMarkupWriter.csCreates a writer that emits HTML markup to the given output.
public HtmlMarkupWriter(TextWriter output)Parameters
outputTextWriter
Properties
| Name | Description |
|---|---|
| Depth | The number of elements, between the root and the node being written, whose start tag is written: 0 for the root element and for the children of a root document; the children of an element are at the depth of the element plus 1. |
| Output | The writer the markup is written to. |
| Root | The node passed to HtmlMarkupWriter.Write. |
| StyleAttributeFormatter | The formatter of the value of the style attributes (see HtmlMarkupWriter.WriteAttributes), or null to write it as is. HtmlFormatter.Format sets it to HtmlFormatter.StyleAttributeFormatter when it is null. |
| StyleElementFormatter | The formatter of the CSS text of the style elements (see HtmlMarkupWriter.WriteRawText), or null to write it as is. HtmlFormatter.Format sets it to HtmlFormatter.StyleElementFormatter when it is null. |
Depth
HtmlMarkupWriter.csOutput
HtmlMarkupWriter.csStyleAttributeFormatter
HtmlMarkupWriter.csThe formatter of the value of the style attributes (see HtmlMarkupWriter.WriteAttributes), or null to write it as is. HtmlFormatter.Format sets it to HtmlFormatter.StyleAttributeFormatter when it is null.
public CssFormatter? StyleAttributeFormatter { get; set; }Property value
StyleElementFormatter
HtmlMarkupWriter.csThe formatter of the CSS text of the style elements (see HtmlMarkupWriter.WriteRawText), or null to write it as is. HtmlFormatter.Format sets it to HtmlFormatter.StyleElementFormatter when it is null.
public CssFormatter? StyleElementFormatter { get; set; }Property value
Methods
| Name | Description |
|---|---|
| ShouldWrite(Node) | Returns whether node and its descendants are written. Returns true by default. |
| Write(Node) | Writes node: an element with its start tag, its descendants and its end tag (as the outerHTML getter), the children of a document or a document fragment. |
| WriteAttribute(Element, string, string) | Writes an attribute of the element: a space, then name="value" with the value escaped. |
| WriteAttributes(Element) | Calls HtmlMarkupWriter.WriteAttribute for each attribute of the element, preceded by the is value of the element when it has one but no is attribute. The value of the style attribute is formatted by HtmlMarkupWriter.StyleAttributeFormatter when it is set. |
| WriteComment(Comment) | Writes <!--data-->. |
| WriteDocumentType(DocumentType) | Writes <!DOCTYPE name>: as defined by the serialization algorithm, the public and system identifiers are not written. |
| WriteEndTag(Element) | Writes the end tag of the element. It is not called for the void elements (HtmlFormatter.IsVoidElement). |
| WriteProcessingInstruction(ProcessingInstruction) | Writes <?target data?>. |
| WriteRawText(Text) | Writes a text node whose parent has raw text content (HtmlFormatter.HasRawTextContent): as is, or for a style element, the text of its style sheet formatted by HtmlMarkupWriter.StyleElementFormatter in place of its first text node (its other text nodes are not written). |
| WriteStartTag(Element) | Writes the start tag of the element: <, the tag name, the attributes (HtmlMarkupWriter.WriteAttributes) and >. |
| WriteText(Text) | Writes a text node: with HtmlMarkupWriter.WriteRawText when its parent has raw text content (HtmlFormatter.HasRawTextContent), escaped otherwise. |
ShouldWrite(Node)
HtmlMarkupWriter.csWrite(Node)
HtmlMarkupWriter.csWriteAttribute(Element, string, string)
HtmlMarkupWriter.csWrites an attribute of the element: a space, then name="value" with the value escaped.
Parameters
elementElement- The element of the attribute.
serializedNamestring- The name of the attribute, prefixed as defined by
HtmlFormatter.GetSerializedAttributeName. valuestring- The value of the attribute.
WriteAttributes(Element)
HtmlMarkupWriter.csCalls HtmlMarkupWriter.WriteAttribute for each attribute of the element, preceded by the is value of the element when it has one but no is attribute. The value of the style attribute is formatted by HtmlMarkupWriter.StyleAttributeFormatter when it is set.
Parameters
elementElement
WriteComment(Comment)
HtmlMarkupWriter.csWriteDocumentType(DocumentType)
HtmlMarkupWriter.csWrites <!DOCTYPE name>: as defined by the serialization algorithm, the public and system identifiers are not written.
protected virtual void WriteDocumentType(DocumentType documentType)Parameters
documentTypeDocumentType
WriteEndTag(Element)
HtmlMarkupWriter.csWrites the end tag of the element. It is not called for the void elements (HtmlFormatter.IsVoidElement).
Parameters
elementElement
WriteProcessingInstruction(ProcessingInstruction)
HtmlMarkupWriter.csWrites <?target data?>.
protected virtual void WriteProcessingInstruction(ProcessingInstruction processingInstruction)Parameters
processingInstructionProcessingInstruction
WriteRawText(Text)
HtmlMarkupWriter.csWrites a text node whose parent has raw text content (HtmlFormatter.HasRawTextContent): as is, or for a style element, the text of its style sheet formatted by HtmlMarkupWriter.StyleElementFormatter in place of its first text node (its other text nodes are not written).
Parameters
textText
WriteStartTag(Element)
HtmlMarkupWriter.csWrites the start tag of the element: <, the tag name, the attributes (HtmlMarkupWriter.WriteAttributes) and >.
Parameters
elementElement
WriteText(Text)
HtmlMarkupWriter.csWrites a text node: with HtmlMarkupWriter.WriteRawText when its parent has raw text content (HtmlFormatter.HasRawTextContent), escaped otherwise.
Parameters
textText