Documentation
¶
Overview ¶
Package rawhtml lets the HTML written in a document's markdown through to the viewers, cleaned. CommonMark allows raw HTML, such as a link written as <a href="...">, <kbd>, <sub> or <details>; goldmark in its safe mode leaves it all out. Here each piece of raw HTML goes through an allowlist instead, as GitHub cleans a README: text formatting, links, lists, tables and the like stay, with only the attributes that can't run anything or change the page around them.
Images and image maps (<img usemap>, <map>, <area>) stay too, but what an image loads is up to the viewer, through Options.Image, as it is for a markdown image.
What never gets through: scripts, styles and event handlers; forms, frames and embeds; id, class and style attributes, and name anywhere but on a <map>, which could reach the viewer's own elements and CSS; and links and image sources other than http:, https:, mailto: and relative ones.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Options ¶
type Options struct {
// Image is given each <img>'s src and alt, cleaned, and returns the
// src the image should load. When it returns "", the image is left
// out, and replace, HTML the viewer trusts, such as a note that the
// image wasn't loaded, is put in its place. Nil leaves out every
// image.
Image func(src, alt string) (load string, replace string)
}
Options are the viewer's say over raw HTML.