code

package
v0.3.2 Latest Latest
Warning

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

Go to latest
Published: May 5, 2026 License: MIT Imports: 21 Imported by: 0

Documentation

Overview

Package code provides constructors and methods for the HTML <code> element.

The <code> HTML element displays its contents styled in a fashion intended to indicate that the text is a short fragment of computer code. By default, the content text is displayed using the user agent's default monospace font.

Index

Constants

This section is empty.

Variables

View Source
var (
	TagOpen  = []byte("<code")
	TagClose = []byte("</code>")
)

Byte constants for HTML rendering.

Functions

func New

func New(nodes ...node.Node) *element

New creates a new code element with the given child nodes. Example: code.New(text.Text("console.log('Hello, World!');")) Renders: <code>console.log('Hello, World!');</code>

func RawText

func RawText(str string) *element

RawText creates a new code element with raw text content. Uses text.RawText which is not HTML-escaped. Example: code.RawText("fmt.Println()") Renders: <code>fmt.Println()</code>

func RawTextf

func RawTextf(format string, args ...any) *element

RawTextf creates a new code element with formatted raw text content. Uses text.RawTextf which is not HTML-escaped. Example: code.RawTextf("fmt.%s()", "Println") Renders: <code>fmt.Println()</code>

func Static

func Static(str string) *element

Static creates a new code element with static text content. Uses text.Static which is not HTML-escaped and is JIT-optimisable. Example: code.Static("fmt.Println()") Renders: <code>fmt.Println()</code>

func Text

func Text(str string) *element

Text creates a new code element with text content. Uses text.Text which HTML-escapes the output. Example: code.Text("fmt.Println()") Renders: <code>fmt.Println()</code>

func Textf

func Textf(format string, args ...any) *element

Textf creates a new code element with formatted text content. Uses text.Textf which HTML-escapes the output. Example: code.Textf("fmt.%s()", "Println") Renders: <code>fmt.Println()</code>

Types

type Element

type Element = element

Element is an exported alias for the private element type

Jump to

Keyboard shortcuts

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