Involved Source Files Package html implements HTML renderer of parsed markdown document.
Configuring and customizing a renderer
A renderer can be configured with multiple options:
import "github.com/gomarkdown/markdown/html"
flags := html.CommonFlags | html.CompletePage | html.HrefTargetBlank
opts := html.RendererOptions{
Title: "A custom title",
Flags: flags,
}
renderer := html.NewRenderer(opts)
You can also re-use most of the logic and customize rendering of selected nodes
by providing node render hook.
This is most useful for rendering nodes that allow for design choices, like
links or code blocks.
import (
"github.com/gomarkdown/markdown/html"
"github.com/gomarkdown/markdown/ast"
)
// a very dummy render hook that will output "code_replacements" instead of
// <code>${content}</code> emitted by html.Renderer
func renderHookCodeBlock(w io.Writer, node ast.Node, entering bool) (ast.WalkStatus, bool) {
_, ok := node.(*ast.CodeBlock)
if !ok {
return ast.GoToNext, false
}
io.WriteString(w, "code_replacement")
return ast.GoToNext, true
}
opts := html.RendererOptions{
RenderNodeHook: renderHookCodeBlock,
}
renderer := html.NewRenderer(opts)renderer.gosmartypants.go
Renderer implements Renderer interface for HTML output.
Do not create this directly, instead use the NewRenderer function. if > 0, will strip html tags in Out and Outs IsSafeURLOverride allows overriding the default URL matcher. URL is
safe if the overriding function returns true. Can be used to extend
the default list of safe URLs.OptsRendererOptions CR writes a new line Callout writes ast.Callout node Caption writes ast.Caption node CaptionFigure writes ast.CaptionFigure node Citation writes ast.Citation node Code writes ast.Code node CodeBlock writes ast.CodeBlock node DocumentMatter writes ast.DocumentMatter(*Renderer) EnsureUniqueHeadingID(id string) string EscapeHTMLCallouts writes html-escaped d to w. It escapes &, <, > and " characters, *but*
expands callouts <<N>> with the callout HTML, i.e. by calling r.callout() with a newly created
ast.Callout node. HTMLBlock write ast.HTMLBlock node HTMLSpan writes ast.HTMLSpan node HardBreak writes ast.Hardbreak node Heading writes ast.Heading node(*Renderer) HeadingEnter(w io.Writer, hdr *ast.Heading)(*Renderer) HeadingExit(w io.Writer, hdr *ast.Heading) HorizontalRule writes ast.HorizontalRule node Image writes ast.Image node Index writes ast.Index node Link writes ast.Link node List writes ast.List node ListItem writes ast.ListItem node(*Renderer) MakeUniqueHeadingID(hdr *ast.Heading) string NonBlockingSpace writes ast.NonBlockingSpace node Out is a helper to write data to writer(*Renderer) OutHRTag(w io.Writer, attrs []string) OutOneOf writes first or second depending on outFirst OutOneOfCr writes CR + first or second + CR depending on outFirst(*Renderer) OutTag(w io.Writer, name string, attrs []string) Outs is a helper to write data to writer Paragraph writes ast.Paragraph node RenderFooter writes HTML document footer. RenderHeader writes HTML document preamble and TOC if requested. RenderNode renders a markdown node to HTML TableBody writes ast.TableBody node TableCell writes ast.TableCell node Text writes ast.Text node
*Renderer : github.com/gomarkdown/markdown.Renderer
func NewRenderer(opts RendererOptions) *Renderer
RendererOptions is a collection of supplementary parameters tweaking
the behavior of various parts of HTML renderer. Prepend this text to each relative URL. // Optional CSS file URL (used if CompletePage is set) CitationFormatString defines how a citation is rendered. If blank, the string
<sup>[%s]</sup> is used. Where %s will be substituted with the citation target. Comments is a list of comments the renderer should detect when
parsing code blocks and detecting callouts. // Flags allow customizing this renderer's behavior Add this text to each footnote anchor, to ensure uniqueness. Show this text inside the <a> tag for a footnote return link, if the
FootnoteReturnLinks flag is enabled. If blank, the string
<sup>[return]</sup> is used. Generator is a meta tag that is inserted in the generated HTML so show what rendered it. It should not include the closing tag.
Defaults (note content quote is not closed) to ` <meta name="GENERATOR" content="github.com/gomarkdown/markdown markdown processor for Go` // Optional head data injected in the <head> section (used if CompletePage is set) If set, add this text to the front of each Heading ID, to ensure uniqueness. If set, add this text to the back of each Heading ID, to ensure uniqueness. // Optional icon file URL (used if CompletePage is set) can over-write <p> for paragraph tag if set, called at the start of RenderNode(). Allows replacing
rendering of some nodes // Document title (used if CompletePage is set)
func NewRenderer(opts RendererOptions) *Renderer
RenderNodeFunc allows reusing most of Renderer logic and replacing
rendering of some nodes. If it returns false, Renderer.RenderNode
will execute its logic. If it returns true, Renderer.RenderNode will
skip rendering this node and will return WalkStatus
SPRenderer is a struct containing state of a Smartypants renderer. Process is the entry point of the Smartypants renderer.
func NewSmartypantsRenderer(flags Flags) *SPRenderer
TODO: move to internal package
Create a url-safe slug for fragments
TagWithAttributes creates a HTML tag with a given name and attributes
Package-Level Variables (total 2)
Escaper defines how to escape HTML special characters
IDTag is the tag used for tag identification, it defaults to "id", some renderers
may wish to override this and use e.g. "anchor".
Package-Level Constants (total 22)
HTML renderer configuration options.
HTML renderer configuration options.
HTML renderer configuration options.
HTML renderer configuration options.
HTML renderer configuration options.
HTML renderer configuration options.
HTML renderer configuration options.
HTML renderer configuration options.
HTML renderer configuration options.
HTML renderer configuration options.
HTML renderer configuration options.
HTML renderer configuration options.
HTML renderer configuration options.
HTML renderer configuration options.
HTML renderer configuration options.
HTML renderer configuration options.
HTML renderer configuration options.
HTML renderer configuration options.
HTML renderer configuration options.
HTML renderer configuration options.
HTML renderer configuration options.
HTML renderer configuration options.
The pages are generated with Goldsv0.8.2. (GOOS=linux GOARCH=amd64)
Golds is a Go 101 project developed by Tapir Liu.
PR and bug reports are welcome and can be submitted to the issue list.
Please follow @zigo_101 (reachable from the left QR code) to get the latest news of Golds.