HyperTextExpression.AspNetCore 0.0.7

dotnet add package HyperTextExpression.AspNetCore --version 0.0.7                
NuGet\Install-Package HyperTextExpression.AspNetCore -Version 0.0.7                
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.AspNetCore" Version="0.0.7" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add HyperTextExpression.AspNetCore --version 0.0.7                
#r "nuget: HyperTextExpression.AspNetCore, 0.0.7"                
#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.AspNetCore as a Cake Addin
#addin nuget:?package=HyperTextExpression.AspNetCore&version=0.0.7

// Install HyperTextExpression.AspNetCore as a Cake Tool
#tool nuget:?package=HyperTextExpression.AspNetCore&version=0.0.7                

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

Custom Serialization

  1. Implement IPrintHtml
public class MyPrintHtml : IPrintHtml
{
    public void Write(char c) => ...;
    public void Write(char c, int count) => ...;
    public void Write(ReadOnlySpan<char> chars) => ...;
}
  1. Dump HtmlEl to your implementation of IPrintHtml
var html = HtmlDoc(
        Body(
            ("h1", "Hello World")
        ));
        
var myPrint = new MyPrintHtml();
        
IPrintHtml.To(html, myPrint);
Product 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.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
0.0.7 371 8/19/2023
0.0.6 181 8/5/2023
0.0.5 186 7/30/2023
0.0.4 177 7/30/2023
0.0.3 178 7/30/2023