Command Palette

Search for a command to run...

UnylyUnyly
Назад к скиллам

element-html-builder

БесплатноБез исполняемых скриптовНе проверен

Element is a zero dependency library to efficiently generate HTML, without templates in Go

rohanthewizот rohanthewiz★ 16 звёзд на GitHub18 установок в других каталогах

Об этом скилле

Element - AI Agent Documentation

Programmatic HTML generation in Go without templates.

Overview

Element is a zero-dependency Go library that generates HTML programmatically by leveraging Go's natural function execution order. Instead of templates, you write Go code that mirrors HTML's tree structure.

Benefits

  1. You never leave the safety, speed, and familiarity of Go
    • Compiles single-pass with the rest of your Go program -- no extra annotations or build steps
    • All of Go is available at any point in your code
  2. Zero dependencies
  3. Buffer pools and component caching for super-high traffic situations
  4. Go's formatting naturally follows the HTML tree structure
  5. Deterministic output: attributes render in the order you pass them

Installation

go get -u github.com/rohanthewiz/element

General Strategy

  1. Write the opening tag with attributes
  2. Render the children and closing tag

Core Concepts

The Builder Pattern

All HTML generation flows through a Builder instance. The builder maintains an internal buffer where tags are written immediately upon method calls.

Immediate Tag Writing

Key Insight: When you call a builder method like b.Div(), the opening tag <div> is written immediately to an internal buffer. The returned element must be terminated with R(), T(), or F() to write the closing tag.

b := element.NewBuilder()
b.Div("id", "container")  // "<div id="container">" is NOW in the buffer
// The element is returned, waiting for termination

Go's function argument evaluation order means children are processed (and their tags written) before the parent's R() closes the parent tag. This is what makes nested structures work correctly.

Terminate all tags

Every non-self-closing element must be terminated with R(), T(), or F(). Self-closing elements like Br, Img, Input, Hr, and Meta don't require termination, but to keep things consistent, close these tags with a sole R() or T().

Basic Usage

Creating a Builder

import "github.com/rohanthewiz/element"

// Standard creation
b := element.NewBuilder()

// Shorthand (equivalent)
b := element.B()

// From pool (for high-throughput HTTP handlers)
b := element.AcquireBuilder()
defer element.ReleaseBuilder(b)

Deprecated: element.Vars(), element.V(), b.Funcs(), b.Vars(), b.V() are deprecated. Use element.B() or element.NewBuilder() instead.

Simple Elements

b := element.B()

// Element with text content
b.P().T("Hello, World!")
// Output: <p>Hello, World!</p>

// Element with children
b.Div().R(
    b.P().T("First paragraph"),
    b.P().T("Second paragraph"),
)
// Output: <div><p>First paragraph</p><p>Second paragraph</p></div>

// Empty element
b.Div().R()
// Output: <div></div>

// Get the HTML string
html := b.String()

Complete Page Example

b := element.B()
// b.Html() automatically prepends <!DOCTYPE html> — no separate DOCTYPE needed
b.Html().R(
    b.Head().R(
        b.Title().T("My Page"),
        b.Meta("charset", "utf-8").R(),
    ),
    b.Body().R(
        b.DivClass("container").R(
            b.H1().T("Welcome"),
            b.P().T("Hello from Element!"),
        ),
    ),
)
html := b.String()

Building with Multiple Functions

func main() {
	b := element.B()

	b.DivClass("container").R(
		b.H2().T("Section 1"),
		generateList(b),
	)

	fmt.Println(b.Pretty())
	/* // Output:
	<div class="container">
	  <h2>Section 1</h2>
	  <ul>
	    <li>Item 1</li>
	    <li>Item 2</li>
	  </ul>
	</div>
	 */
}

func generateList(b *element.Builder) (x any) { // we don't care about the return
	// Everything is rendered in the builder immediately!
	b.Ul().R(
		b.Li().T("Item 1"),
		b.Li().T("Item 2"),
	)
	return
}

API Reference

Builder Creation

Function Description
element.NewBuilder() Create a new builder
element.B() Shorthand for NewBuilder()
element.AcquireBuilder() Get builder from pool (high-throughput)
element.ReleaseBuilder(b) Return builder to pool

Termination Methods

Method Use Case Example
R(children...) Elements with children or empty b.Div().R(b.P().T("hi"))
T(strings...) Text-only content you authored — written verbatim, NOT escaped b.P().T("Hello")
TE(strings...) Text-only content from anywhere else — HTML-escaped b.Td().TE(user.Name)
F(format, args...) Formatted text (like fmt.Sprintf) — NOT escaped b.P().F("Count: %d", 42)

Escaping: T vs TE

T() and F() write their arguments verbatim

Полный SKILL.md на GitHub

Установить element-html-builder в Claude Code и Claude Desktop

Зарегайся, чтобы установить скилл

Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.

  • Открой команду установки в одну строку
  • Сохраняй скиллы в синхронизируемую библиотеку
  • Уведомления, когда скиллы обновляются
Зарегаться бесплатноУ меня уже есть аккаунт

Разрешённые инструменты

Инструменты, которые скиллу разрешено вызывать.

Без ограничений — скилл может использовать любой инструмент.

Вложенные файлы

ARCHITECTURE.mdbacklog/IMPLEMENTATION_PROPOSALS.mdclaude_sessions/2026-0701-2033-perf-low-hanging-fruit.mdclaude_sessions/2026-0704-1219-components-overhaul.mdclaude_sessions/2026-0706-1357-playground-yaegi-wasm-tutorial.mdclaude_sessions/2026-0706-1540-playground-deploy-splitter-pretty.mdclaude_sessions/2026-0706-1800-go-learn platform build and deploy.mdclaude_sessions/2026-0706-1835-go-learn worker runner backport.mdclaude_sessions/2026-0817-1155-attribute-value-escaping-and-TE.md

FAQ

Что делает скилл element-html-builder?

Element is a zero dependency library to efficiently generate HTML, without templates in Go

Как установить скилл element-html-builder?

Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.

Скилл element-html-builder запускает скрипты?

Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.

Похожие скиллы

Сравнить element-html-builder с