htmlRenderer

package module
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Sep 12, 2022 License: MIT Imports: 10 Imported by: 1

README

htmlRenderer

This is a personal fork of the Goldmark HTML renderer. I would encourage you not to use it, but if you really want to, you can find the docs here and you can install it as shown:

go get github.com/codemicro/htmlRenderer

Documentation

Index

Constants

This section is empty.

Variables

View Source
var BlockquoteAttributeFilter = GlobalAttributeFilter.Extend(
	[]byte("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 DefaultWriter = &defaultWriter{}

DefaultWriter is a default implementation of the Writer.

View Source
var EmphasisAttributeFilter = GlobalAttributeFilter

EmphasisAttributeFilter defines attribute names which emphasis elements can have.

View Source
var GlobalAttributeFilter = util.NewBytesFilter(
	[]byte("accesskey"),
	[]byte("autocapitalize"),
	[]byte("autofocus"),
	[]byte("class"),
	[]byte("contenteditable"),
	[]byte("dir"),
	[]byte("draggable"),
	[]byte("enterkeyhint"),
	[]byte("hidden"),
	[]byte("id"),
	[]byte("inert"),
	[]byte("inputmode"),
	[]byte("is"),
	[]byte("itemid"),
	[]byte("itemprop"),
	[]byte("itemref"),
	[]byte("itemscope"),
	[]byte("itemtype"),
	[]byte("lang"),
	[]byte("part"),
	[]byte("slot"),
	[]byte("spellcheck"),
	[]byte("style"),
	[]byte("tabindex"),
	[]byte("title"),
	[]byte("translate"),
)

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.Extend(
	[]byte("align"),
	[]byte("border"),
	[]byte("crossorigin"),
	[]byte("decoding"),
	[]byte("height"),
	[]byte("importance"),
	[]byte("intrinsicsize"),
	[]byte("ismap"),
	[]byte("loading"),
	[]byte("referrerpolicy"),
	[]byte("sizes"),
	[]byte("srcset"),
	[]byte("usemap"),
	[]byte("width"),
)

ImageAttributeFilter defines attribute names which image elements can have.

View Source
var LinkAttributeFilter = GlobalAttributeFilter.Extend(
	[]byte("download"),

	[]byte("hreflang"),
	[]byte("media"),
	[]byte("ping"),
	[]byte("referrerpolicy"),
	[]byte("rel"),
	[]byte("shape"),
	[]byte("target"),
)

LinkAttributeFilter defines attribute names which link elements can have.

View Source
var ListAttributeFilter = GlobalAttributeFilter.Extend(
	[]byte("start"),
	[]byte("reversed"),
	[]byte("type"),
)

ListAttributeFilter defines attribute names which list elements can have.

View Source
var ListItemAttributeFilter = GlobalAttributeFilter.Extend(
	[]byte("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 ThematicAttributeFilter = GlobalAttributeFilter.Extend(
	[]byte("align"),
	[]byte("color"),
	[]byte("noshade"),
	[]byte("size"),
	[]byte("width"),
)

ThematicAttributeFilter defines attribute names which hr elements can have.

Functions

func IsDangerousURL

func IsDangerousURL(url []byte) bool

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

func NewProcessor added in v0.1.1

func NewProcessor(renderOptions ...renderer.Option) goldmark.Markdown

NewProcessor creates a new instance of goldmark.Markdown for processing Markdown

func NewRenderer

func NewRenderer(opts ...Option) renderer.NodeRenderer

NewRenderer returns a new Renderer with given options.

func RenderAttributes

func RenderAttributes(w util.BufWriter, node ast.Node, filter util.BytesFilter)

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 WithExternalLinkProtection

func WithExternalLinkProtection(currentHost string) interface {
	renderer.Option
	Option
}

WithExternalLinkProtection renders anchors to external sites with rel="noopener noreferrer".

func WithHardWraps

func WithHardWraps() interface {
	renderer.Option
	Option
}

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

func WithHeaderLinks() interface {
	renderer.Option
	Option
}

WithHeaderLinks renders anchors next to Markdown titles with their IDs.

func WithUnsafe

func WithUnsafe() interface {
	renderer.Option
	Option
}

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

func WithWriter

func WithWriter(writer Writer) interface {
	renderer.Option
	Option
}

WithWriter is a functional option that allow you to set the given writer to the renderer.

func WithXHTML

func WithXHTML() interface {
	Option
	renderer.Option
}

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

Types

type Config

type Config struct {
	Writer                 Writer
	HardWraps              bool
	XHTML                  bool
	Unsafe                 bool
	HeaderLinks            bool
	ExternalLinkProtection bool

	CurrentHost string
}

A Config struct has configurations for the HTML based renderers.

func NewConfig

func NewConfig() Config

NewConfig returns a new Config with defaults.

func (*Config) SetOption

func (c *Config) SetOption(name renderer.OptionName, value interface{})

SetOption implements renderer.NodeRenderer.SetOption.

type Option

type Option interface {
	SetHTMLOption(*Config)
}

An Option interface sets options for HTML based renderers.

type Renderer

type Renderer struct {
	Config
}

A Renderer struct is an implementation of renderer.NodeRenderer that renders nodes as (X)HTML.

func (*Renderer) RegisterFuncs

func (r *Renderer) RegisterFuncs(reg renderer.NodeRendererFuncRegisterer)

RegisterFuncs implements NodeRenderer.RegisterFuncs .

type Writer

type Writer interface {
	// Write writes the given source to writer with resolving references and unescaping
	// backslash escaped characters.
	Write(writer util.BufWriter, source []byte)

	// RawWrite writes the given source to writer without resolving references and
	// unescaping backslash escaped characters.
	RawWrite(writer util.BufWriter, source []byte)

	// SecureWrite writes the given source to writer with replacing insecure characters.
	SecureWrite(writer util.BufWriter, source []byte)
}

A Writer interface writes textual contents to a writer.

Jump to

Keyboard shortcuts

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