html

package module
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 19, 2023 License: Apache-2.0 Imports: 6 Imported by: 1

README

HTML rendering library

status stable go.dev reference

HTML is a Go library for writing HTML similar to React components.

Example

Applications can rendern their user interface like in this example examples/html.go. You can run it by running go run ./examples. Full code of this demo:

package main

import (
	"fmt"

	"github.com/mbertschler/html"
	"github.com/mbertschler/html/attr"
)

func main() {
	root := html.Blocks{
		// Option 1: directly add an element
		html.Doctype("html"),
		html.Html(nil,
			// Option 2: struct that implements Block interface (RenderHTML() Block)
			HeadBlock{attr.Name("key").Content("super")},
			// Option 3: function that returns a Block
			BodyBlock("Hello, world! :) <br>"),
		),
	}
	out, err := html.RenderString(root)
	if err != nil {
		fmt.Println("Error:", err)
	}
	fmt.Println(out)

	out, err = html.RenderMinifiedString(root)
	if err != nil {
		fmt.Println("Error:", err)
	}
	fmt.Println(out)
}

type HeadBlock struct {
	attr.Attributes
}

func (h HeadBlock) RenderHTML() html.Block {
	return html.Head(nil,
		html.Meta(h.Attributes),
	)
}

func BodyBlock(in string) html.Block {
	return html.Body(nil,
		html.Main(attr.Class("main-class\" href=\"/evil/link"),
			html.H1(nil,
				html.Text(in),
				html.Br(nil),
				html.UnsafeString(in),
			),
		),
	)
}

License

Blocks is released under the Apache 2.0 license. See LICENSE.

Documentation

Overview

Code generated by cmd/generate. DO NOT EDIT.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Render

func Render(w io.Writer, root Block) error

func RenderMinified

func RenderMinified(w io.Writer, root Block) error

func RenderMinifiedString

func RenderMinifiedString(root Block) (string, error)

func RenderString

func RenderString(root Block) (string, error)

Types

type Block

type Block interface {
	RenderHTML() Block
}

func A

func A(attr attr.Attributes, children ...Block) Block

func Abbr

func Abbr(attr attr.Attributes, children ...Block) Block

func Address

func Address(attr attr.Attributes, children ...Block) Block

func Area

func Area(attr attr.Attributes, children ...Block) Block

func Article

func Article(attr attr.Attributes, children ...Block) Block

func Aside

func Aside(attr attr.Attributes, children ...Block) Block

func Audio

func Audio(attr attr.Attributes, children ...Block) Block

func B

func B(attr attr.Attributes, children ...Block) Block

func Base

func Base(attr attr.Attributes, children ...Block) Block

func Bdi

func Bdi(attr attr.Attributes, children ...Block) Block

func Bdo

func Bdo(attr attr.Attributes, children ...Block) Block

func Blockquote

func Blockquote(attr attr.Attributes, children ...Block) Block

func Body

func Body(attr attr.Attributes, children ...Block) Block

func Br

func Br(attr attr.Attributes) Block

func Button

func Button(attr attr.Attributes, children ...Block) Block

func Canvas

func Canvas(attr attr.Attributes, children ...Block) Block

func Caption

func Caption(attr attr.Attributes, children ...Block) Block

func Cite

func Cite(attr attr.Attributes, children ...Block) Block

func Code

func Code(attr attr.Attributes, children ...Block) Block

func Col

func Col(attr attr.Attributes, children ...Block) Block

func Colgroup

func Colgroup(attr attr.Attributes, children ...Block) Block

func Data

func Data(attr attr.Attributes, children ...Block) Block

func Datalist

func Datalist(attr attr.Attributes, children ...Block) Block

func Dd

func Dd(attr attr.Attributes, children ...Block) Block

func Del

func Del(attr attr.Attributes, children ...Block) Block

func Details

func Details(attr attr.Attributes, children ...Block) Block

func Dfn

func Dfn(attr attr.Attributes, children ...Block) Block

func Dialog

func Dialog(attr attr.Attributes, children ...Block) Block

func Div

func Div(attr attr.Attributes, children ...Block) Block

func Dl

func Dl(attr attr.Attributes, children ...Block) Block

func Doctype

func Doctype(arg string) Block

func Dt

func Dt(attr attr.Attributes, children ...Block) Block

func Elem

func Elem(el string, attr attr.Attributes, children ...Block) Block

func Em

func Em(attr attr.Attributes, children ...Block) Block

func Embed

func Embed(attr attr.Attributes, children ...Block) Block

func Fieldset

func Fieldset(attr attr.Attributes, children ...Block) Block

func Figcaption

func Figcaption(attr attr.Attributes, children ...Block) Block

func Figure

func Figure(attr attr.Attributes, children ...Block) Block
func Footer(attr attr.Attributes, children ...Block) Block

func Form

func Form(attr attr.Attributes, children ...Block) Block

func H1

func H1(attr attr.Attributes, children ...Block) Block

func H2

func H2(attr attr.Attributes, children ...Block) Block

func H3

func H3(attr attr.Attributes, children ...Block) Block

func H4

func H4(attr attr.Attributes, children ...Block) Block

func H5

func H5(attr attr.Attributes, children ...Block) Block

func H6

func H6(attr attr.Attributes, children ...Block) Block
func Head(attr attr.Attributes, children ...Block) Block
func Header(attr attr.Attributes, children ...Block) Block

func Hgroup

func Hgroup(attr attr.Attributes, children ...Block) Block

func Hr

func Hr(attr attr.Attributes) Block

func Html

func Html(attr attr.Attributes, children ...Block) Block

func I

func I(attr attr.Attributes, children ...Block) Block

func Iframe

func Iframe(attr attr.Attributes, children ...Block) Block

func Img

func Img(attr attr.Attributes) Block

func Input

func Input(attr attr.Attributes) Block

func Ins

func Ins(attr attr.Attributes, children ...Block) Block

func Kbd

func Kbd(attr attr.Attributes, children ...Block) Block

func Label

func Label(attr attr.Attributes, children ...Block) Block

func Legend

func Legend(attr attr.Attributes, children ...Block) Block

func Li

func Li(attr attr.Attributes, children ...Block) Block
func Link(attr attr.Attributes) Block

func Main

func Main(attr attr.Attributes, children ...Block) Block

func Map

func Map(attr attr.Attributes, children ...Block) Block

func Mark

func Mark(attr attr.Attributes, children ...Block) Block
func Menu(attr attr.Attributes, children ...Block) Block

func Meta

func Meta(attr attr.Attributes) Block

func Meter

func Meter(attr attr.Attributes, children ...Block) Block
func Nav(attr attr.Attributes, children ...Block) Block

func Noscript

func Noscript(attr attr.Attributes, children ...Block) Block

func Object

func Object(attr attr.Attributes, children ...Block) Block

func Ol

func Ol(attr attr.Attributes, children ...Block) Block

func Optgroup

func Optgroup(attr attr.Attributes, children ...Block) Block

func Option

func Option(attr attr.Attributes, children ...Block) Block

func Output

func Output(attr attr.Attributes, children ...Block) Block

func P

func P(attr attr.Attributes, children ...Block) Block

func Picture

func Picture(attr attr.Attributes, children ...Block) Block

func Portal

func Portal(attr attr.Attributes, children ...Block) Block

func Pre

func Pre(attr attr.Attributes, children ...Block) Block

func Progress

func Progress(attr attr.Attributes, children ...Block) Block

func Q

func Q(attr attr.Attributes, children ...Block) Block

func Rp

func Rp(attr attr.Attributes, children ...Block) Block

func Rt

func Rt(attr attr.Attributes, children ...Block) Block

func Ruby

func Ruby(attr attr.Attributes, children ...Block) Block

func S

func S(attr attr.Attributes, children ...Block) Block

func Samp

func Samp(attr attr.Attributes, children ...Block) Block

func Script

func Script(attr attr.Attributes, children ...Block) Block

func Section

func Section(attr attr.Attributes, children ...Block) Block

func Select

func Select(attr attr.Attributes, children ...Block) Block

func Slot

func Slot(attr attr.Attributes, children ...Block) Block

func Small

func Small(attr attr.Attributes, children ...Block) Block

func Source

func Source(attr attr.Attributes, children ...Block) Block

func Span

func Span(attr attr.Attributes, children ...Block) Block

func Strong

func Strong(attr attr.Attributes, children ...Block) Block

func Style

func Style(attr attr.Attributes, children ...Block) Block

func Sub

func Sub(attr attr.Attributes, children ...Block) Block

func Summary

func Summary(attr attr.Attributes, children ...Block) Block

func Sup

func Sup(attr attr.Attributes, children ...Block) Block

func Table

func Table(attr attr.Attributes, children ...Block) Block

func Tbody

func Tbody(attr attr.Attributes, children ...Block) Block

func Td

func Td(attr attr.Attributes, children ...Block) Block

func Template

func Template(attr attr.Attributes, children ...Block) Block

func Textarea

func Textarea(attr attr.Attributes, children ...Block) Block

func Tfoot

func Tfoot(attr attr.Attributes, children ...Block) Block

func Th

func Th(attr attr.Attributes, children ...Block) Block

func Thead

func Thead(attr attr.Attributes, children ...Block) Block

func Time

func Time(attr attr.Attributes, children ...Block) Block

func Title

func Title(attr attr.Attributes, children ...Block) Block

func Tr

func Tr(attr attr.Attributes, children ...Block) Block

func Track

func Track(attr attr.Attributes, children ...Block) Block

func U

func U(attr attr.Attributes, children ...Block) Block

func Ul

func Ul(attr attr.Attributes, children ...Block) Block

func Var

func Var(attr attr.Attributes, children ...Block) Block

func Video

func Video(attr attr.Attributes, children ...Block) Block

func Wbr

func Wbr(attr attr.Attributes, children ...Block) Block

type Blocks

type Blocks []Block

func (*Blocks) Add

func (b *Blocks) Add(block Block)

func (*Blocks) AddBlocks

func (b *Blocks) AddBlocks(blocks Blocks)

func (Blocks) RenderHTML

func (Blocks) RenderHTML() Block

type CSS

type CSS template.CSS

func (CSS) RenderHTML

func (CSS) RenderHTML() Block

type Comment

type Comment string

func (Comment) RenderHTML

func (Comment) RenderHTML() Block

type Element

type Element struct {
	Type string
	attr.Attributes
	Children Blocks
	Options  ElementOption
}

func (Element) RenderHTML

func (Element) RenderHTML() Block

type ElementOption

type ElementOption int8
const (
	Void ElementOption = 1 << iota
	CSSElement
	JSElement
	NoWhitespace
)

type HTML

type HTML template.HTML

func (HTML) RenderHTML

func (HTML) RenderHTML() Block

type HTMLAttr

type HTMLAttr template.HTMLAttr

func (HTMLAttr) RenderHTML

func (HTMLAttr) RenderHTML() Block

type JS

type JS template.JS

func (JS) RenderHTML

func (JS) RenderHTML() Block

type JSStr

type JSStr template.JSStr

func (JSStr) RenderHTML

func (JSStr) RenderHTML() Block

type Text

type Text string

func (Text) RenderHTML

func (Text) RenderHTML() Block

type URL

type URL template.URL

func (URL) RenderHTML

func (URL) RenderHTML() Block

type UnsafeString

type UnsafeString string

func (UnsafeString) RenderHTML

func (UnsafeString) RenderHTML() Block

Directories

Path Synopsis
Code generated by cmd/generate; DO NOT EDIT.
Code generated by cmd/generate; DO NOT EDIT.
cmd

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL