HyperTextExpression 0.0.4
There is a newer version of this package available.
See the version list below for details.
See the version list below for details.
dotnet add package HyperTextExpression --version 0.0.4
NuGet\Install-Package HyperTextExpression -Version 0.0.4
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="HyperTextExpression" Version="0.0.4" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add HyperTextExpression --version 0.0.4
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: HyperTextExpression, 0.0.4"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install HyperTextExpression as a Cake Addin #addin nuget:?package=HyperTextExpression&version=0.0.4 // Install HyperTextExpression as a Cake Tool #tool nuget:?package=HyperTextExpression&version=0.0.4
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
HyperTextExpression
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()
);
Motivation
- 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
Installation
Standalone
dotnet add package HyperTextExpression
AspNetCore Integration
dotnet add package HyperTextExpression.AspNetCore
Examples
If you've never seen Uncle Bob's mythical "tests as documentation", here you go
Custom Serialization
- 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
toIPrint
var html = HtmlDoc(
Body(
("h1", "Hello World")
));
var myPrint = new MyPrintHtml();
IPrintHtml.To(html, myPrint);
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net7.0 is compatible. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
net7.0
- No dependencies.
NuGet packages (1)
Showing the top 1 NuGet packages that depend on HyperTextExpression:
Package | Downloads |
---|---|
HyperTextExpression.AspNetCore
Minimal HTML DSL. |
GitHub repositories
This package is not used by any popular GitHub repositories.