Documentation
¶
Overview ¶
Package markdown renders editor content. Content is stored as Markdown; raw HTML in the source is never rendered: goldmark drops each HTML block and inline tag and writes <!-- raw HTML omitted --> in its place (the text between inline tags stays). Media is referenced as  and resolved to a public URL at render time.
Index ¶
- Constants
- func AbsoluteSrcset(base, srcset string) string
- func HTML(source string, resolve Resolver) template.HTML
- func Links(source string) []string
- func MediaIDs(source string) []string
- func PlainMedia(source string, options Options) string
- func Render(source string, options Options) template.HTML
- func Text(source string) string
- type Image
- type ImageResolver
- type Options
- type Resolver
Constants ¶
const MediaPrefix = "media:"
MediaPrefix marks a link or image destination that refers to a media asset.
Variables ¶
This section is empty.
Functions ¶
func AbsoluteSrcset ¶
AbsoluteSrcset makes every address of srcset, such as "/a.webp 480w, /b.webp 800w", absolute from base, as Options.Base does with the srcset of an image Images gives; the descriptors (480w) stay as they are. An empty base, or one that is not an absolute address, leaves srcset as it is.
func Links ¶
Links returns the distinct destinations of the links in source, in order, as written: those of text(address) and reference links, and the web addresses GFM turns into links, such as https://example.com. Links to media assets are media:<uuid>; images are not links.
func PlainMedia ¶
PlainMedia is source for readers of the Markdown itself, such as the text part of an e-mail, with its media references resolved by options: an image becomes a link to the image, [alt](address), with the alt text of options.Images when the Markdown gives none and the address of options.Images or else options.Media; a link to media gets the address of options.Media. A reference that does not resolve keeps its text. With options.Base, the destinations of links and images outside code are resolved from it, as Render does.
Types ¶
type Image ¶
Image is how an image asset is shown: the address of its src and, optionally, a srcset with sizes, the alt text used when the Markdown gives none, and the size of URL in pixels for the img's width and height attributes, so the browser keeps the image's place before it loads (0 leaves them out).
type ImageResolver ¶
ImageResolver describes the image asset id. alt is the image's description in the Markdown; when it is empty, Image.Alt is used instead. ok is false when the resolver has nothing to add to Options.Media.
type Options ¶
type Options struct {
// Media turns a media ID into a public URL, for links and images; nil
// leaves media links empty.
Media Resolver
// Images describes media images; nil, or an image it has nothing for,
// uses Media's URL alone.
Images ImageResolver
// Base makes the site's own addresses absolute, for readers away from
// the site, such as a feed or an e-mail. It is the absolute address
// the content's relative links lead from, such as
// "https://example.com/en/": link and image destinations without a
// scheme are resolved from it as a browser resolves them, both paths
// on the site ("/en/about" becomes "https://example.com/en/about") and
// relative addresses ("about" becomes "https://example.com/en/about"),
// also those Media and Images give, every address of an image's
// srcset among them. Addresses with a scheme
// ("https://…", "mailto:…") and a fragment alone ("#top") stay as they
// are. Empty, or not an absolute address, leaves every destination as
// it is.
Base string
}
Options are how Render resolves media.