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 (Autowire) ¶
package main import ( "context" "strings" "github.com/bounoable/postdog/autowire" "github.com/bounoable/postdog/letter" ) func main() { config := ` plugins: - name: markdown use: goldmark ` cfg, err := autowire.Load(strings.NewReader(config)) if err != nil { panic(err) } po, err := cfg.Office(context.Background()) if err != nil { panic(err) } err = po.Send(context.Background(), letter.Write( letter.Text("# Heading 1\n# Heading 2"), )) }
Output:
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() { po := postdog.New( postdog.WithPlugin( markdown.Plugin( gm.Converter(goldmark.New()), // use goldmark Markdown parser markdown.OverrideHTML(true), // plugin options ), ), ) err := po.Send(context.Background(), letter.Write( letter.Text("# Heading 1\n# Heading 2"), // The HTML body of the letter will be replaced with the generated HTML )) _ = err }
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() { po := postdog.New( postdog.WithPlugin( markdown.Plugin(gm.Converter(goldmark.New())), ), ) ctx := markdown.Disable(context.Background()) // disable Markdown conversion for this context po.Send(ctx, letter.Write(letter.Text("# Heading"))) // letter.HTML will stay empty }
Output:
Index ¶
- Variables
- func AutowirePlugin(_ context.Context, cfg map[string]interface{}) (postdog.Plugin, error)
- 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
- func Register(cfg *autowire.Config)
- func RegisterConverter(name string, factory ConverterFactory)
- type Config
- type Converter
- type ConverterFactory
- type ConverterFactoryFunc
- type ConverterFunc
- type Option
- type UnregisteredConverterError
Examples ¶
Constants ¶
This section is empty.
Variables ¶
var (
// Name is the plugin name.
Name = "markdown"
)
Functions ¶
func AutowirePlugin ¶ added in v0.4.0
AutowirePlugin creates the Markdown plugin from the autowire config.
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.
func RegisterConverter ¶ added in v0.4.0
func RegisterConverter(name string, factory ConverterFactory)
RegisterConverter registers a converter factory for the given converter name for autowiring.
Types ¶
type Config ¶
type Config struct { // Override HTML field even if it's already filled. OverrideHTML bool }
Config is the plugin configuration.
type ConverterFactory ¶ added in v0.4.0
ConverterFactory creates the Markdown converter from the autowire config.
type ConverterFactoryFunc ¶ added in v0.4.0
ConverterFactoryFunc allows functions to be used as a ConverterFactory.
func (ConverterFactoryFunc) CreateConverter ¶ added in v0.4.0
func (fn ConverterFactoryFunc) CreateConverter(cfg map[string]interface{}) (Converter, error)
CreateConverter creates the Markdown converter from the autowire config.
type ConverterFunc ¶
ConverterFunc allows a function to be used as Converter.
type Option ¶
type Option func(*Config)
Option is a plugin option.
func OverrideHTML ¶
OverrideHTML overrides the HTML body of the letter, even if it is already filled.
type UnregisteredConverterError ¶ added in v0.4.0
type UnregisteredConverterError struct {
Name string
}
UnregisteredConverterError means the autowire config defines the plugin with an unregistered converter name.
func (UnregisteredConverterError) Error ¶ added in v0.4.0
func (err UnregisteredConverterError) Error() string
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. |