Compose HTML structures with C#.
The H class is a factory class that makes it easier to build html tags. Examples: H.B("some bold text") & H.Div().AddElement(H.Img("http://..."))
Short example of some commonly used compositions.
H.Div()
.WithId("story-45")
.AddClass("my-styory")
.AddElement(H.H4("A story"))
.AddElement(H.P("This is a awesome story."))
.AddElement(H.A("#", "Read More..."));Show how to add attributes, pluss smome helper methods like AddStyle and AddClass
H.Span("Some Text")
.WithId("span-99")
.AddClass("my-span")
.AddStyle("color", "red")
.AddAttribute("my-attribute", "123")If you want to create custome tags use the H.ValueTag("my-custome-tag") and H.EmptyTag("my-custome-tag").
H.EmptyTag("my-empty-tag")
.AddAttribute("some-attribute", "...");
H.ValueTag("my-value-tag")
.AddAttribute("some-attribute", "...")
.AddElement(H.Span("..."));
<my-empty-tag some-attribute="..." />
<my-value-tag some-attribute="...">
<span>...</span>
</my-value-tag>The add if methods are usefull if you want to have conditional adds without breaking the composition.
H.Div()
.AddElementIf(true, H.B("some text"))
.AddClassIf(true, "some-class"))
.AddStyleIf(true, "color", "red")
.AddElement("some text");This is the core interface for composing Html code. Classes using this interface must implement ToString(). The ToString() is used for rendering the html.
| HtmlEmptyTag | Self closing tags like <img />. These are tags that does not contain other elements. |
| HtmlValueTag | Tags like <div></div>. These can contain other tags like this. <div><b>Child tag</b></div>. |
| HtmlComment | A normal html comment like this <!-- a comment --> |
| HtmlText | If you want to just add text without any html. |
| HtmlList | An array of elements. Has no markup. Renders the markup of it's items. |
| HtmlEmpty | Renders nothing. |
| HtmlPage | Helping class for building a full Html page. |
The HtmlAttribute is a simple class with a name and value property. Attributes can be added to the HtmlEmptyTag and HtmlValueTag.