Documentation
¶
Overview ¶
Package emailmd renders Markdown into what a newsletter needs: email HTML with every style inlined (mail clients ignore most stylesheets), clean HTML for the web archive, and a readable plain-text part.
Index ¶
- Constants
- Variables
- func CheckImage(p string, data []byte) (string, error)
- func Email(l Layout) (string, error)
- func FrontMatter(src string) (map[string]string, string)
- func Inline(fragment string, t Theme) string
- func Local(src string) bool
- func LocalImages(source string) []string
- func MarkButtons(fragment string) string
- func RewriteImages(fragment string, fn func(src string) string) string
- func RewriteLinks(fragment string, fn func(i int, href string) string) string
- func Text(source string) string
- type Doc
- type Layout
- type Theme
Constants ¶
const ( MaxImage = 1 << 20 // bytes HeavyImage = 300 << 10 // above this, an image slows the issue down )
Image limits: formats every mail client shows (Outlook shows neither WebP nor SVG), small enough that an issue stays quick on a phone.
Variables ¶
var DefaultTheme = Theme{
Accent: "#0f766e",
Font: `-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,Helvetica,Arial,sans-serif`,
}
DefaultTheme reads well everywhere.
var ImageTypes = map[string]string{"image/jpeg": ".jpg", "image/png": ".png", "image/gif": ".gif"}
ImageTypes maps the accepted content types to file extensions.
Functions ¶
func CheckImage ¶
CheckImage validates an image file an issue references: a clean relative path and an accepted format within the size limit. It returns the type.
func FrontMatter ¶
FrontMatter splits optional "---" key: value lines from the body.
func Inline ¶
Inline adds inline styles to rendered HTML for email. A paragraph holding nothing but one link whose text ends in "→" becomes a button.
func LocalImages ¶
LocalImages returns the image sources of Markdown that are paths, not URLs: files next to the Markdown that must be uploaded with it.
func MarkButtons ¶
MarkButtons gives the button links of a web fragment class="button".
func RewriteImages ¶
RewriteImages replaces the src of every image in an HTML fragment.
func RewriteLinks ¶
RewriteLinks replaces every http(s) href in fragment with fn(index, url), counting in document order like Doc.Links.
Types ¶
type Doc ¶
type Doc struct {
HTML string // semantic HTML for the web
Title string // text of the first heading
Summary string // text of the first paragraph
Links []string // http(s) link targets in document order, duplicates kept
}
Doc is rendered Markdown.
type Layout ¶
type Layout struct {
Lang string
Title string // subject
Preheader string // preview text shown by inboxes after the subject
Brand string // list name, shown above the content
BrandURL string
Body template.HTML // inlined content
Pixel string // open-tracking image URL, empty when off
Theme Theme
}
Layout is the frame around a newsletter.