Documentation
¶
Overview ¶
Package html implements renderer that outputs HTMLs.
Index ¶
- Variables
- func ContextHTMLWriter(rc renderer.Context) util.BufWriter
- func ContextLinkURLWriter(rc renderer.Context) util.BufWriter
- func ContextTextWriter(rc renderer.Context) util.BufWriter
- func IsDangerousURL(url string) bool
- func IsInTightBlock(n ast.Node) bool
- func RenderAttributes(writer io.Writer, source []byte, node ast.Node, filter util.BytesFilter, ...)
- type Config
- type Extension
- type IsInTightBlockFunc
- type LineBreakStrategy
- type NodeRenderer
- type NodeRendererDecorator
- type Option
- func WithExtensions(extensions ...Extension) Option
- func WithHardWraps() Option
- func WithIsInTightBlockFunc(fn IsInTightBlockFunc) Option
- func WithLineBreakStrategy(strategy LineBreakStrategy) Option
- func WithNodeRenderer(kind ast.NodeKind, nodeRenderer NodeRenderer) Option
- func WithNodeRendererDecorator(kind ast.NodeKind, decorator NodeRendererDecorator) Option
- func WithNodeRendererDecorators(decorators map[ast.NodeKind]NodeRendererDecorator) Option
- func WithNodeRenderers(nodeRenderers map[ast.NodeKind]NodeRenderer) Option
- func WithUnsafe() Option
- func WithXHTML() Option
- type ParagraphConfig
- type Renderer
Constants ¶
This section is empty.
Variables ¶
var BlockquoteAttributeFilter = GlobalAttributeFilter.ExtendString(`cite`)
BlockquoteAttributeFilter defines attribute names which blockquote elements can have.
var CodeAttributeFilter = GlobalAttributeFilter
CodeAttributeFilter defines attribute names which code elements can have.
var EmphasisAttributeFilter = GlobalAttributeFilter
EmphasisAttributeFilter defines attribute names which emphasis elements can have.
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.
var HeadingAttributeFilter = GlobalAttributeFilter
HeadingAttributeFilter defines attribute names which heading elements can have.
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.
var LinkAttributeFilter = GlobalAttributeFilter.ExtendString(`download,href,lang,media,ping,referrerpolicy,rel,shape,target`) // nolint:lll
LinkAttributeFilter defines attribute names which link elements can have.
var ListAttributeFilter = GlobalAttributeFilter.ExtendString(`start,reversed,type`)
ListAttributeFilter defines attribute names which list elements can have.
var ListItemAttributeFilter = GlobalAttributeFilter.ExtendString(`value`)
ListItemAttributeFilter defines attribute names which list item elements can have.
var ParagraphAttributeFilter = GlobalAttributeFilter
ParagraphAttributeFilter defines attribute names which paragraph elements can have.
var StrongAttributeFilter = GlobalAttributeFilter
StrongAttributeFilter defines attribute names which strong elements can have.
var ThematicAttributeFilter = GlobalAttributeFilter.ExtendString(`align,color,noshade,size,width`)
ThematicAttributeFilter defines attribute names which hr elements can have.
Functions ¶
func ContextHTMLWriter ¶
ContextHTMLWriter returns a writer that writes HTML content.
func ContextLinkURLWriter ¶
ContextLinkURLWriter returns a writer that writes link URL content.
func ContextTextWriter ¶
ContextTextWriter returns a writer that writes text content.
func IsDangerousURL ¶
IsDangerousURL returns true if the given url seems a potentially dangerous url, otherwise false.
func IsInTightBlock ¶
IsInTightBlock returns true if the paragraph is a direct child of a ListItem whose parent List is tight.
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.
type Extension ¶
Extension is an extension that extends HTML based renderers.
func NewCommonMark ¶
NewCommonMark returns a new Extension that renders CommonMark compliant HTML.
type IsInTightBlockFunc ¶
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 ¶
Option is a functional option for HTML based renderers.
func WithExtensions ¶
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.
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.