r/Protos • • 3d ago

HTML without templates: building a structured HTML library entirely in a prototype-based programming language

Protos, a prototype-based programming language running on GraalVM, now includes a structured HTML generation library written entirely in Protos itself.

The approach is comparable to Python's Dominate, Haskell's Lucid and Swift HTML libraries: compose HTML using ordinary language constructs rather than a separate template language.

Html: import("std:html")

div: Html.div
h1: Html.h1
p: Html.p

Html.render(
    div(
        h1("Hello, Protos!"),
        p("HTML as ordinary data")
    )
)

The library provides:

  • 58 HTML tag constructors.
  • Reusable components through ordinary closures.
  • Automatic contextual escaping.
  • Deterministic serialization and resource limits.
  • Ordinary structured objects instead of a privileged HTML value type.
  • Zero new production Java code.

All 110 HTML conformance tests pass locally.

The interesting question is how much of a programming language's standard library can be implemented in the language itself without introducing additional runtime primitives.

For developers familiar with Python, Ruby, Haskell or Smalltalk: which approach to programmatic HTML generation do you prefer, and why?

Source: https://github.com/guillermomolina/protos

More language development updates in r/ProtosLang.

1 Upvotes

0 comments sorted by