Documentation ¶
Overview ¶
Package markdown provides Markdown support for letters. It registers a middleware that converts the text body of letters with a Markdown converter and sets the HTML body to the conversion result.
Example (Basic) ¶
package main import ( "context" "github.com/bounoable/postdog" "github.com/bounoable/postdog/letter" "github.com/bounoable/postdog/plugin/markdown" gm "github.com/bounoable/postdog/plugin/markdown/goldmark" "github.com/yuin/goldmark" ) func main() { off := postdog.New( postdog.WithPlugin( markdown.Plugin( gm.Converter(goldmark.New()), // use goldmark Markdown parser markdown.OverrideHTML(true), // plugin options ), ), ) off.Send(context.Background(), letter.Write(letter.Text("# Heading"))) // letter.HTML will be set to <h1>Heading</h1> }
Output:
Example (Disable) ¶
package main import ( "context" "github.com/bounoable/postdog" "github.com/bounoable/postdog/letter" "github.com/bounoable/postdog/plugin/markdown" gm "github.com/bounoable/postdog/plugin/markdown/goldmark" "github.com/yuin/goldmark" ) func main() { off := postdog.New( postdog.WithPlugin( markdown.Plugin(gm.Converter(goldmark.New())), ), ) ctx := markdown.Disable(context.Background()) // disable Markdown conversion for this context off.Send(ctx, letter.Write(letter.Text("# Heading"))) // letter.HTML will stay empty }
Output:
Index ¶
- func Disable(ctx context.Context) context.Context
- func Disabled(ctx context.Context) bool
- func Enable(ctx context.Context) context.Context
- func Enabled(ctx context.Context) bool
- func Plugin(conv Converter, opts ...Option) postdog.PluginFunc
- func PluginWithConfig(conv Converter, cfg Config) postdog.PluginFunc
- type Config
- type Converter
- type ConverterFunc
- type Option
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Plugin ¶
func Plugin(conv Converter, opts ...Option) postdog.PluginFunc
Plugin is the install function for the Markdown plugin. It takes the Text field of the outgoing letters, converts them and sets the HTML field to the result.
func PluginWithConfig ¶
func PluginWithConfig(conv Converter, cfg Config) postdog.PluginFunc
PluginWithConfig is the install function for the Markdown plugin. It takes the Text field of the outgoing letters, converts them and sets the HTML field to the result.
Types ¶
type Config ¶
type Config struct { // Override HTML field even if it's already filled. OverrideHTML bool }
Config is the plugin configuration.
type ConverterFunc ¶
ConverterFunc allows a function to be used as Converter.
Directories ¶
Path | Synopsis |
---|---|
Package goldmark provides an adapter for the goldmark Markdown parser.
|
Package goldmark provides an adapter for the goldmark Markdown parser. |
Package mock_markdown is a generated GoMock package.
|
Package mock_markdown is a generated GoMock package. |
Click to show internal directories.
Click to hide internal directories.