Documentation ¶
Index ¶
- Constants
- func GetDomain(ctx context.Context) string
- func GetState[V any](ctx context.Context, key string) V
- func ParseAndEncodeQuery(rawQuery string) string
- func SetState[V any](ctx context.Context, key string, val V)
- func UpdateState[V any](ctx context.Context, key string, fn func(V) V)
- func WithEscapeMode(mode escapeMode) converterOption
- func WithPlugins(plugins ...Plugin) converterOption
- type AssembleAbsoluteURLFunc
- type Context
- type ConvertOptionFunc
- type Converter
- type GetStateFunc
- type HandlePostRenderFunc
- type HandlePreRenderFunc
- type HandleRenderFunc
- type HandleTextTransformFunc
- type HandleUnEscapeFunc
- type Plugin
- type RenderStatus
- type SetStateFunc
- type UpdateStateFunc
- type Writer
Constants ¶
const ( EscapeModeDisabled escapeMode = "disabled" EscapeModeSmart escapeMode = "smart" )
const ( // PriorityEarly means that the handler will be run **early** in the process. // To run it even earlier you need to subtract from this number. PriorityEarly = 100 // PriorityStandard is for handlers that don't need to be run in a particular order. PriorityStandard = 500 // PriorityLate means that the handler will be run **late** in the process. // To run it even later you need to add to this number. PriorityLate = 1000 )
const ( TagTypeBlock tagType = "block" TagTypeInline tagType = "inline" // TagTypeRemove will remove that node in the _PreRender_ phase with a high priority. TagTypeRemove tagType = "remove" )
Variables ¶
This section is empty.
Functions ¶
func ParseAndEncodeQuery ¶
func WithEscapeMode ¶
func WithEscapeMode(mode escapeMode) converterOption
WithEscapeMode changes the strictness of the "escaping".
Some characters have a special meaning in markdown. For example, the character "*" can be used for lists, emphasis and dividers. By placing a backlash before that character (e.g. "\*") you can "escape" it. Then the character will render as a raw "*" without the "markdown meaning" applied.
Learn more in the documentation
"disabled" or "smart" default: "smart"
func WithPlugins ¶
func WithPlugins(plugins ...Plugin) converterOption
WithPlugins can be used to add additional functionality to the converter.
Types ¶
type AssembleAbsoluteURLFunc ¶
type Context ¶
type Context interface { context.Context AssembleAbsoluteURL(ctx Context, tagName string, rawURL string) string GetTagType(tagName string) (tagType, bool) RenderNodes(ctx Context, w Writer, nodes ...*html.Node) RenderChildNodes(ctx Context, w Writer, n *html.Node) EscapeContent(content []byte) []byte UnEscapeContent(content []byte) []byte WithValue(key any, val any) Context }
Context extends the normal context.Context with some additional methods useful for the process of converting.
type ConvertOptionFunc ¶ added in v2.2.0
type ConvertOptionFunc func(o *convertOption)
func WithContext ¶
func WithContext(ctx context.Context) ConvertOptionFunc
func WithDomain ¶
func WithDomain(domain string) ConvertOptionFunc
WithDomain provides a base `domain` to the converter and to the `AssembleAbsoluteURL` function.
If a *relative* url is encountered (in an image or link) then the `domain` is used to convert it to a *absolute* url.
type Converter ¶
type Converter struct { Register register // contains filtered or unexported fields }
func NewConverter ¶
func NewConverter(opts ...converterOption) *Converter
func (*Converter) ConvertNode ¶
ConvertNode converts a `*html.Node` to a markdown byte slice.
If you have already parsed an HTML page using the `html.Parse()` function from the "golang.org/x/net/html" package then you can pass this node directly to the converter.
func (*Converter) ConvertReader ¶
ConvertReader converts the html from the reader to markdown.
Under the hood `html.Parse()` is used to parse the HTML.
func (*Converter) ConvertString ¶
func (conv *Converter) ConvertString(htmlInput string, opts ...ConvertOptionFunc) (string, error)
ConvertString converts a html-string to a markdown-string.
Under the hood `html.Parse()` is used to parse the HTML.
type GetStateFunc ¶
type HandlePostRenderFunc ¶
type HandlePreRenderFunc ¶
type HandleRenderFunc ¶
type HandleRenderFunc func(ctx Context, w Writer, n *html.Node) RenderStatus
type HandleTextTransformFunc ¶
type HandleUnEscapeFunc ¶
type Plugin ¶
type Plugin interface { // The public name of the plugin, e.g. "strikethrough" Name() string // Init is called to initialize the plugin. It can be used to // *validate* the arguments and *register* the rules. Init(conv *Converter) error }
Plugin can be used to extends functionality beyond what is offered by commonmark.