Skip to content

A dsl embedded in the C# language for generating HTML documents.

License

Notifications You must be signed in to change notification settings

sholland1/HtmlDsl

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

21 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

HtmlDsl

This library is a dsl embedded in the C# language for generating HTML documents. It is inspired by the Lucid library from Haskell. It is intended as an alternative to the ASP.NET Razor templating system.

Example usage:

using HtmlDsl;
using static HtmlDsl.Tags;
.
.
IHtml Evens(int n) =>
    _ul(Enumerable
            .Range(0, n)
            .Where(x => x % 2 == 0)
            .Select(x => _li($"{x}"))
            .ToArray());

string readmeExample =
    _html(
        _head(
            _title("HtmlDsl README")),
        _body(
            _comment("This is a comment."),
            _h1(("id", "myHeader"))("HtmlDsl"),
            _br(),
            _div(
                _div(("id", "inner-div"),
                     ("name", "inner"))
                    (_span("This library is ", _i("very"), " cool!")),
            Evens(10))))
    .Render();

Example output (formatted for readability):

<html>
  <head>
    <title>HtmlDsl README</title>
  </head>
  <body>
    <!--This is a comment.-->
    <h1 id="myHeader">HtmlDsl</h1>
    <br />
    <div>
      <div id="inner-div" name="inner">
        <span>This library is <i>very</i> cool!</span>
      </div>
      <ul>
        <li>0</li>
        <li>2</li>
        <li>4</li>
        <li>6</li>
        <li>8</li>
      </ul>
    </div>
  </body>
</html>

About

A dsl embedded in the C# language for generating HTML documents.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages