Same ol' C# with a different way to say what HTML you want.
using static HyperTextExpression.HtmlExp;
var html = HtmlDoc(
("body", Children(
("article",
Attrs(
("class", "body"),
("show", "")
),
Enumerable.Range(1, 6)
.Select(i =>
("p",
Attrs("class", "paragraph"),
$"Lorem Ipsum {i}")))))
);
html.ToString(); => <!DOCTYPE html>
<html>
<body>
<article class="body" show>
<p class="paragraph">Lorem Ipsum 1</p>
<p class="paragraph">Lorem Ipsum 2</p>
<p class="paragraph">Lorem Ipsum 3</p>
<p class="paragraph">Lorem Ipsum 4</p>
<p class="paragraph">Lorem Ipsum 5</p>
<p class="paragraph">Lorem Ipsum 6</p>
</article>
</body>
</html>
Within ASP.NET Core.
app.MapGet("/", () =>
HtmlDoc(
Body(
("h1", "Hello World")
))
.ToIResult()
);
- Template straight in c#
- No need to use/learn
.cshtml
Razor/View and then wait for things like email templating... - C# structure is MUCH easier to manipulate than an HTML string.
- hiccup
- tweet
dotnet add package HyperTextExpression
dotnet add package HyperTextExpression.AspNetCore
- If you've never seen Uncle Bob's mythical "tests as documentation", here you go
- Samples with Htmx
- Implement
IPrintHtml
public class MyPrintHtml : IPrintHtml
{
public void Write(char c) => ...;
public void Write(char c, int count) => ...;
public void Write(ReadOnlySpan<char> chars) => ...;
}
- Dump
HtmlEl
to your implementation ofIPrintHtml
var html = HtmlDoc(
Body(
("h1", "Hello World")
));
var myPrint = new MyPrintHtml();
IPrintHtml.To(html, myPrint);