codeblock

package
v0.1.5 Latest Latest
Warning

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

Go to latest
Published: Aug 3, 2026 License: MIT Imports: 16 Imported by: 0

Documentation

Overview

templ: version: v0.3.1020

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Render

func Render(code, lang string) string

Render returns a Chroma-highlighted <pre><code>…</code></pre> fragment as raw HTML, suitable for injection via templ.Raw.

Token spans use the "ch-" class prefix; css/codeblock.css maps a small subset of those classes to a 4-color palette. Unknown languages fall back to plain (escaped) text inside <pre><code>.

Types

type Config

type Config struct {
	// Language selects the Chroma lexer (e.g. "go", "bash", "html", "css").
	// "templ" aliases to the Go lexer. Unknown values fall back to plain text.
	Language string
	// Code is the source code to display
	Code string
	// Label is the header text (defaults to Language if empty)
	Label string
	// MaxHeight is an optional CSS max-height for scrollable long code (e.g. "400px")
	MaxHeight string
	// Density controls spacing in the header and highlighted code body.
	Density Density
	// ID overrides the auto-generated element ID
	ID string
}

Config holds configuration for the code block component

type Density added in v0.1.5

type Density string

Density controls spacing inside code block regions.

const (
	// DensityDefault uses standard documentation spacing.
	DensityDefault Density = ""
	// DensityCompact reduces header and code padding for short snippets.
	DensityCompact Density = "compact"
)

type Instance added in v0.0.12

type Instance struct {
	// contains filtered or unexported fields
}

Instance is a renderable code block component.

func CodeBlock

func CodeBlock(cfg Config) Instance

CodeBlock returns a renderable code block component.

func (Instance) Kind added in v0.0.12

func (Instance) Kind() components.Kind

Kind identifies the component as a code block.

func (Instance) Render added in v0.0.12

func (i Instance) Render(ctx context.Context, w io.Writer) error

Render writes the code block markup.

Jump to

Keyboard shortcuts

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