-
-
Notifications
You must be signed in to change notification settings - Fork 4
bookgen.api.htmlbuilder
Namespace: BookGen.Api
A builder class for generating HTML content in a fluent manner.
public sealed class HtmlBuilderInheritance Object → HtmlBuilder
Attributes NullableContextAttribute, NullableAttribute
Remarks:
Initializes a new instance of the HtmlBuilder class with the specified initial capacity.
Gets the name of the last unclosed HTML tag, or null if there are no open tags.
public string? LastUnclosedTag { get; }Gets an enumerable of all currently open HTML tags in reverse order (from the most recently opened to the least).
public IEnumerable<string> OpenTags { get; }A builder class for generating HTML content in a fluent manner.
public HtmlBuilder(int size)size Int32
The initial capacity of the underlying StringBuilder.
Remarks:
Initializes a new instance of the HtmlBuilder class with the specified initial capacity.
Creates a new instance of HtmlBuilder with the specified initial capacity.
public static HtmlBuilder Create(int size = 4096)size Int32
The initial capacity of the underlying StringBuilder.
HtmlBuilder
A new instance of HtmlBuilder.
Creates an HTML element with the specified tag name and optional content.
public HtmlBuilder Element(string tag, Action<HtmlBuilder>? content = null)tag String
The name of the HTML tag.
content Action<HtmlBuilder>?
An optional action to generate the content of the element.
HtmlBuilder
The current HtmlBuilder instance.
Creates an HTML element with the specified tag name, attributes, and optional content.
public HtmlBuilder Element(string tag, Action<TagBuilder> configure, Action<HtmlBuilder>? content = null)tag String
The name of the HTML tag.
configure Action<TagBuilder>
An action to configure the attributes of the tag.
content Action<HtmlBuilder>?
An optional action to generate the content of the element.
HtmlBuilder
The current HtmlBuilder instance.
Closes the most recently opened HTML element.
public HtmlBuilder CloseOpenTag()HtmlBuilder
The current HtmlBuilder instance.
InvalidOperationException
Thrown if there are no open elements to close.
Appends text content to the current HTML element, encoding it to prevent XSS attacks.
public HtmlBuilder Text(string text)text String
The text content to append.
HtmlBuilder
The current HtmlBuilder instance.
Appends raw HTML content to the current HTML element without encoding.
public HtmlBuilder Raw(string html)html String
The raw HTML content to append.
HtmlBuilder
The current HtmlBuilder instance.
Creates a self-closing HTML element with the specified tag name and optional attributes.
public HtmlBuilder SelfClosing(string tag, Action<TagBuilder>? configure = null)tag String
The name of the HTML tag.
configure Action<TagBuilder>?
An optional action to configure the attributes of the tag.
HtmlBuilder
The current HtmlBuilder instance.
Returns the generated HTML content as a string. Throws an exception if there are unclosed HTML elements.
public override string ToString()String
The generated HTML content as a string.
InvalidOperationException
Thrown if there are unclosed HTML elements.