markdown

package
v0.0.39 Latest Latest
Warning

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

Go to latest
Published: Feb 27, 2026 License: MIT Imports: 15 Imported by: 0

Documentation

Overview

templ: version: v0.3.977

Index

Constants

View Source
const PreviewPath = "/preview/markdown"

PreviewPath is the standard handler path for markdown preview.

Variables

This section is empty.

Functions

func Markdown

func Markdown(props Props) templ.Component

Markdown renders markdown content as HTML. It uses GitHub Flavored Markdown with typography extensions.

func MarkdownInput

func MarkdownInput(props InputProps) templ.Component

MarkdownInput renders a textarea with Write/Preview tabs. Clicking Preview sends the markdown to the server via POST SSE, which renders it and patches the preview div.

func MustRender

func MustRender(markdown string) string

MustRender converts markdown to HTML, returning empty string on error. Errors are logged for debugging but do not cause panics. Raw HTML tags in the input are escaped for security.

func PreviewHandler

func PreviewHandler() http.HandlerFunc

PreviewHandler returns an http.HandlerFunc that renders markdown from the component's signals and patches the preview div via SSE.

Mount at a dedicated POST path:

r.Post(markdown.PreviewPath, markdown.PreviewHandler())

func Render

func Render(markdown string) (string, error)

Render converts markdown text to HTML. Raw HTML tags in the input are escaped for security.

func Route added in v0.0.31

func Route() func(chi.Router)

Route returns a RouteOption that registers the markdown preview handler.

Types

type InputProps

type InputProps struct {
	// ID uniquely identifies this component instance. Required.
	ID string
	// Class adds additional CSS classes to the container.
	Class string
	// Attributes adds arbitrary HTML attributes to the container.
	Attributes templ.Attributes
	// Name is the form field name attribute.
	Name string
	// Placeholder is the textarea placeholder text.
	Placeholder string
	// Value is the initial textarea value.
	Value string
	// PreviewURL is the endpoint path for server-side preview rendering.
	// The component appends "?id=<ID>" automatically.
	PreviewURL string
	// Rows is the textarea rows. Defaults to 8.
	Rows int
}

InputProps configures a markdown input with Write/Preview tabs.

type Props

type Props struct {
	// Content is the markdown text to render.
	Content string
	// ID is the optional element ID.
	ID string
	// Class is additional CSS classes.
	Class string
	// Attributes is additional HTML attributes.
	Attributes templ.Attributes
}

Props configures the Markdown display component.

Jump to

Keyboard shortcuts

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