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 WithContext(ctx context.Context) convertOptionFunc
- func WithDomain(domain string) convertOptionFunc
- func WithPlugins(plugins ...Plugin) converterOption
- type AssembleAbsoluteURLFunc
- type Context
- type Converter
- type Element
- type GetStateFunc
- type HandlePostRenderFunc
- type HandlePreRenderFunc
- type HandleRenderFunc
- type HandleTextTransformFunc
- type HandleUnEscapeFunc
- type Plugin
- type RenderStatus
- type SetStateFunc
- type UpdateStateFunc
- type Writer
Constants ¶
View Source
const ( // StrategyRemoveNode will remove that node in the _PreRender_ phase // with a high priority. StrategyRemoveNode tagStrategy = "StrategyRemoveNode" // StrategyMarkdownLeaf will keep the children of this node as markdown. // // This is the default for unknown nodes — where there // is no registered _Render_ handler. StrategyMarkdownLeaf tagStrategy = "StrategyMarkdownLeaf" // StrategyMarkdownBlock will keep the children of this node as markdown // AND will render newlines. // // This is the default for html nodes that have // a) no registered _Render_ handler AND // b) where `dom.NameIsBlockNode()` returns true. StrategyMarkdownBlock tagStrategy = "StrategyMarkdownBlock" // StrategyHTMLBlock will render the node as HTML using `html.Render()` StrategyHTMLBlock tagStrategy = "StrategyHTMLBlock" // StrategyHTMLBlockWithMarkdown will render the node as HTML // and render the children as markdown. StrategyHTMLBlockWithMarkdown tagStrategy = "StrategyHTMLBlockWithMarkdown" )
View Source
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 )
Variables ¶
This section is empty.
Functions ¶
func ParseAndEncodeQuery ¶
func WithContext ¶
func WithDomain ¶
func WithDomain(domain string) convertOptionFunc
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, elem Element, rawURL string) string GetTagStrategy(tagName string) (tagStrategy, bool) RenderNodes(ctx Context, w Writer, nodes ...*html.Node) RenderChildNodes(ctx Context, w Writer, n *html.Node) 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 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.
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 { // 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.
type SetStateFunc ¶
type UpdateStateFunc ¶
Click to show internal directories.
Click to hide internal directories.