markdown

package
v0.2.2 Latest Latest
Warning

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

Go to latest
Published: Mar 11, 2026 License: MIT Imports: 15 Imported by: 0

Documentation

Overview

Package markdown provides markdown rendering and processing utilities.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Renderer

type Renderer struct {
	// contains filtered or unexported fields
}

Renderer converts markdown content to HTML, extracts titles, and strips markdown to plain text. HTML output is sanitized using bluemonday to prevent XSS attacks from user-submitted markdown.

func New

func New() *Renderer

New creates a new Renderer with default goldmark configuration and HTML sanitization.

func (*Renderer) ExtractHeadings

func (r *Renderer) ExtractHeadings(src []byte) []core.Heading

ExtractHeadings walks the Goldmark AST and extracts H1-H3 headings with their auto-generated IDs and text content, suitable for table of contents rendering.

func (*Renderer) ExtractTitle

func (r *Renderer) ExtractTitle(src []byte) string

ExtractTitle extracts the title from the first H1 heading in the markdown content. If no H1 is found, it returns an empty string.

func (*Renderer) RenderHTML

func (r *Renderer) RenderHTML(src []byte) ([]byte, []core.Heading, error)

RenderHTML parses the markdown source once, extracts H1-H3 headings from the AST for table of contents rendering, then renders the AST to sanitized HTML. This avoids the cost of parsing the same source twice compared to calling ToHTML and ExtractHeadings separately.

func (*Renderer) ToHTML

func (r *Renderer) ToHTML(src []byte) ([]byte, error)

ToHTML converts markdown source to sanitized HTML. The output is sanitized to prevent XSS from crafted markdown inputs.

func (*Renderer) ToPlainText

func (r *Renderer) ToPlainText(src []byte) string

ToPlainText strips markdown formatting and returns plain text content suitable for search indexing.

Jump to

Keyboard shortcuts

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