Documentation
¶
Overview ¶
Package html implements renderer that outputs HTMLs.
Index ¶
- Variables
- func IsDangerousURL(url []byte) bool
- func IsInTightBlock(n ast.Node) bool
- func RenderAttributes(writer io.Writer, node ast.Node, filter util.BytesFilter)
- func WithEscapedSpace() interface{ ... }
- type Config
- type EastAsianLineBreaks
- type EmptyHook
- type Extension
- type Hook
- type IsInTightBlockFunc
- type NodeRenderer
- type Option
- func WithEastAsianLineBreaks(e EastAsianLineBreaks) Option
- func WithExtensions(extensions ...Extension) Option
- func WithHardWraps() Option
- func WithHooks(hooks ...Hook) Option
- func WithIsInTightBlock(fn IsInTightBlockFunc) Option
- func WithNodeRenderer(kind ast.NodeKind, nodeRenderer NodeRenderer) Option
- func WithNodeRenderers(nodeRenderers map[ast.NodeKind]NodeRenderer) Option
- func WithUnsafe() Option
- func WithXHTML() Option
- type ParagraphConfig
- type Renderer
- type Writer
- type WriterOption
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 DefaultWriter = NewWriter()
DefaultWriter is a default instance of the Writer.
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 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.
func RenderAttributes ¶
RenderAttributes renders given node's attributes. You can specify attribute names to render by the filter. If filter is nil, RenderAttributes renders all attributes.
func WithEscapedSpace ¶
func WithEscapedSpace() interface {
WriterOption
Option
}
WithEscapedSpace is a WriterOption indicates that a '\' escaped half-space(0x20) should not be rendered.
Types ¶
type Config ¶
type Config struct {
renderer.Config[io.Writer, Config]
EscapedSpace bool
HardWraps bool
EastAsianLineBreaks EastAsianLineBreaks
XHTML bool
Unsafe bool
Paragraph ParagraphConfig
// contains filtered or unexported fields
}
A Config struct has configurations for the HTML based renderers.
type EastAsianLineBreaks ¶
type EastAsianLineBreaks int
A EastAsianLineBreaks is a style of east asian line breaks.
const ( //EastAsianLineBreaksNone renders line breaks as it is. EastAsianLineBreaksNone EastAsianLineBreaks = iota // EastAsianLineBreaksSimple follows east_asian_line_breaks in Pandoc. EastAsianLineBreaksSimple // EastAsianLineBreaksCSS3Draft follows CSS text level3 "Segment Break Transformation Rules" with some enhancements. EastAsianLineBreaksCSS3Draft )
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 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, rctx renderer.Context) (ast.WalkStatus, error)) NodeRenderer
NodeRendererFunc is a function that renders AST nodes as (X)HTML.
type Option ¶
Option is a functional option for HTML based renderers.
func WithEastAsianLineBreaks ¶
func WithEastAsianLineBreaks(e EastAsianLineBreaks) Option
WithEastAsianLineBreaks is a functional option that indicates whether softline breaks between east asian wide characters should be ignored.
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 WithIsInTightBlock ¶
func WithIsInTightBlock(fn IsInTightBlockFunc) Option
WithIsInTightBlock 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 WithNodeRenderer ¶
func WithNodeRenderer(kind ast.NodeKind, nodeRenderer NodeRenderer) Option
WithNodeRenderer sets a node renderer for the given node kind.
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.
type Writer ¶
type Writer interface {
// WriteText writes the given source to writer with resolving references and unescaping
// backslash escaped characters.
WriteText(writer io.Writer, source []byte)
// RawWriteText writes the given source to writer without resolving references and
// unescaping backslash escaped characters.
RawWriteText(writer io.Writer, source []byte)
// WriteHTML writes the given html.
// WriteHTML replaces null bytes with the replacement character and writes the result to writer.
WriteHTML(writer io.Writer, html []byte)
}
A Writer interface writes textual contents to a writer.
type WriterOption ¶
type WriterOption interface {
SetWriterOption(*writerConfig)
}
A WriterOption interface sets options for HTML based writers.