markdown

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jun 17, 2020 License: MIT Imports: 5 Imported by: 0

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

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Disable

func Disable(ctx context.Context) context.Context

Disable disables Markdown conversions for all letters that are sent with this ctx.

func Disabled

func Disabled(ctx context.Context) bool

Disabled determines if Markdown conversion is disabled for ctx.

func Enable

func Enable(ctx context.Context) context.Context

Enable (re)enables Markdown conversions for ctx.

func Enabled

func Enabled(ctx context.Context) bool

Enabled determines if Markdown conversion is enabled for ctx.

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 Converter

type Converter interface {
	Convert(src []byte, w io.Writer) error
}

Converter converts a Markdown source to HTML.

type ConverterFunc

type ConverterFunc func([]byte, io.Writer) error

ConverterFunc allows a function to be used as Converter.

func (ConverterFunc) Convert

func (fn ConverterFunc) Convert(src []byte, w io.Writer) error

Convert converts the Markdown in src to HTML and writes the result to w.

type Option

type Option func(*Config)

Option is a plugin option.

func OverrideHTML

func OverrideHTML(override bool) Option

OverrideHTML overrides the HTML body of the letter, even if it is already filled.

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.

Jump to

Keyboard shortcuts

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