html

package
v2.0.0 Latest Latest
Warning

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

Go to latest
Published: Aug 27, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package html implements renderer that outputs HTMLs.

Index

Constants

This section is empty.

Variables

View Source
var BlockquoteAttributeFilter = GlobalAttributeFilter.ExtendString(`cite`)

BlockquoteAttributeFilter defines attribute names which blockquote elements can have.

View Source
var CodeAttributeFilter = GlobalAttributeFilter

CodeAttributeFilter defines attribute names which code elements can have.

View Source
var EmphasisAttributeFilter = GlobalAttributeFilter

EmphasisAttributeFilter defines attribute names which emphasis elements can have.

View Source
var GlobalAttributeFilter = util.NewBytesFilterString(`accesskey,autocapitalize,autofocus,class,contenteditable,dir,draggable,enterkeyhint,hidden,id,inert,inputmode,is,itemid,itemprop,itemref,itemscope,itemtype,lang,part,role,slot,spellcheck,style,tabindex,title,translate`) // nolint:lll

GlobalAttributeFilter defines attribute names which any elements can have.

View Source
var HeadingAttributeFilter = GlobalAttributeFilter

HeadingAttributeFilter defines attribute names which heading elements can have.

View Source
var ImageAttributeFilter = GlobalAttributeFilter.ExtendString(`align,border,crossorigin,decoding,height,importance,intrinsicsize,ismap,loading,referrerpolicy,sizes,srcset,usemap,width`) // nolint: lll

ImageAttributeFilter defines attribute names which image elements can have.

View Source
var LinkAttributeFilter = GlobalAttributeFilter.ExtendString(`download,href,lang,media,ping,referrerpolicy,rel,shape,target`) // nolint:lll

LinkAttributeFilter defines attribute names which link elements can have.

View Source
var ListAttributeFilter = GlobalAttributeFilter.ExtendString(`start,reversed,type`)

ListAttributeFilter defines attribute names which list elements can have.

View Source
var ListItemAttributeFilter = GlobalAttributeFilter.ExtendString(`value`)

ListItemAttributeFilter defines attribute names which list item elements can have.

View Source
var ParagraphAttributeFilter = GlobalAttributeFilter

ParagraphAttributeFilter defines attribute names which paragraph elements can have.

View Source
var StrongAttributeFilter = GlobalAttributeFilter

StrongAttributeFilter defines attribute names which strong elements can have.

View Source
var ThematicAttributeFilter = GlobalAttributeFilter.ExtendString(`align,color,noshade,size,width`)

ThematicAttributeFilter defines attribute names which hr elements can have.

Functions

func ContextHTMLWriter

func ContextHTMLWriter(rc renderer.Context) util.BufWriter

ContextHTMLWriter returns a writer that writes HTML content.

func ContextLinkURLWriter

func ContextLinkURLWriter(rc renderer.Context) util.BufWriter

ContextLinkURLWriter returns a writer that writes link URL content.

func ContextTextWriter

func ContextTextWriter(rc renderer.Context) util.BufWriter

ContextTextWriter returns a writer that writes text content.

func IsDangerousURL

func IsDangerousURL(url string) bool

IsDangerousURL returns true if the given url seems a potentially dangerous url, otherwise false.

func IsInTightBlock

func IsInTightBlock(n ast.Node) bool

IsInTightBlock returns true if the paragraph is a direct child of a ListItem whose parent List is tight.

func RenderAttributes

func RenderAttributes(writer io.Writer, source []byte, node ast.Node, filter util.BytesFilter, _ renderer.Context)

RenderAttributes renders the attributes of the given node to the given writer.

Types

type Config

type Config struct {
	renderer.Config[io.Writer, Config]
	HardWraps         bool
	LineBreakStrategy LineBreakStrategy
	XHTML             bool
	Unsafe            bool
	Paragraph         ParagraphConfig
}

A Config struct has configurations for the HTML based renderers.

func (Config) Default

func (c Config) Default() Config

Default returns a Config with default values.

type Extension

type Extension = renderer.Extension[Config]

Extension is an extension that extends HTML based renderers.

func NewCommonMark

func NewCommonMark(opts ...Option) Extension

NewCommonMark returns a new Extension that renders CommonMark compliant HTML.

type IsInTightBlockFunc

type IsInTightBlockFunc func(n ast.Node) bool

IsInTightBlockFunc determines whether a paragraph node is inside a tight block and should be rendered without <p> tags.

type LineBreakStrategy

type LineBreakStrategy interface {
	// SoftLineBreak returns true if a soft line break should be rendered as a new line.
	SoftLineBreak(thisLastRune rune, siblingFirstRune rune) bool
}

LineBreakStrategy is an interface that defines a strategy for determining whether a line break should be rendered as a new line.

var CSSText3LineBreakStrategy LineBreakStrategy = &cssText3LineBreakStrategy{}

CSSText3LineBreakStrategy follows CSS Text Module Level 3 with some enhancements for CJK.

var SimpleEastAsianLineBreakStrategy LineBreakStrategy = &simpleEastAsianLineBreakStrategy{}

SimpleEastAsianLineBreakStrategy follows east_asian_line_breaks in Pandoc.

type NodeRenderer

type NodeRenderer = renderer.NodeRenderer[io.Writer]

NodeRenderer is a renderer that renders AST nodes as (X)HTML.

func NodeRendererFunc

func NodeRendererFunc(f func(w io.Writer, source []byte,
	n ast.Node, entering bool, rc renderer.Context) (ast.WalkStatus, error)) NodeRenderer

NodeRendererFunc adapts f into a NodeRenderer that renders AST nodes as (X)HTML.

type NodeRendererDecorator

type NodeRendererDecorator = renderer.NodeRendererDecorator[io.Writer]

NodeRendererDecorator is a decorator that decorates NodeRenderer.

type Option

type Option = renderer.Option[Config]

Option is a functional option for HTML based renderers.

func WithExtensions

func WithExtensions(extensions ...Extension) Option

WithExtensions adds extensions.

func WithHardWraps

func WithHardWraps() Option

WithHardWraps is a functional option that indicates whether softline breaks should be rendered as '<br>'.

func WithIsInTightBlockFunc

func WithIsInTightBlockFunc(fn IsInTightBlockFunc) Option

WithIsInTightBlockFunc is a functional option that sets a custom function to determine whether a paragraph node is inside a tight block and should be rendered without <p> tags.

func WithLineBreakStrategy

func WithLineBreakStrategy(strategy LineBreakStrategy) Option

WithLineBreakStrategy is a functional option that sets a custom line break strategy.

func WithNodeRenderer

func WithNodeRenderer(kind ast.NodeKind, nodeRenderer NodeRenderer) Option

WithNodeRenderer sets a node renderer for the given node kind.

func WithNodeRendererDecorator

func WithNodeRendererDecorator(kind ast.NodeKind, decorator NodeRendererDecorator) Option

WithNodeRendererDecorator sets a node renderer decorator for the given node kind.

If a decorator is already set for a node kind, the new decorator will be applied to the existing one.

func WithNodeRendererDecorators

func WithNodeRendererDecorators(decorators map[ast.NodeKind]NodeRendererDecorator) Option

WithNodeRendererDecorators sets a node renderer decorator for the given node kind.

If a decorator is already set for a node kind, the new decorator will be applied to the existing one.

func WithNodeRenderers

func WithNodeRenderers(nodeRenderers map[ast.NodeKind]NodeRenderer) Option

WithNodeRenderers sets a node renderer for the given node kind.

func WithUnsafe

func WithUnsafe() Option

WithUnsafe is a functional option that renders dangerous contents (raw htmls and potentially dangerous links) as it is.

func WithXHTML

func WithXHTML() Option

WithXHTML is a functional option indicates that nodes should be rendered in xhtml instead of HTML5.

type ParagraphConfig

type ParagraphConfig struct {
	// IsInTightBlockFunc determines whether a paragraph should be rendered
	// without <p> tags because it is inside a tight block.
	IsInTightBlockFunc IsInTightBlockFunc
}

A ParagraphConfig struct has configurations for paragraph rendering.

type Renderer

type Renderer = renderer.Renderer[io.Writer]

Renderer is a renderer that renders AST nodes as (X)HTML.

func New

func New(opts ...Option) Renderer

New returns a new Renderer with given options.

Jump to

Keyboard shortcuts

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