rawhtml

package
v1.6.0 Latest Latest
Warning

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

Go to latest
Published: Nov 16, 2026 License: MIT Imports: 8 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

func Clean

func Clean(s []byte) []byte

Clean returns s with everything the allowlist doesn't allow taken out. Images are left as they are written; Options.Image is what decides what they load.

func Option

func Option(o Options) renderer.Option

Option renders a document's raw HTML cleaned, in place of goldmark's "raw HTML omitted". Pass it to goldmark.WithRendererOptions; the renderer must not be in unsafe mode, which this replaces.

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.

Jump to

Keyboard shortcuts

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