Core Primitives
核心原语

These primitives make up Paw's rendering core. Most higher-level widgets eventually compose one or more of these types.

这些原语构成了 Paw 的渲染核心。大多数更高层组件最终都会组合其中一种或多种类型。
paw.Listpaw.Stringpaw.Htmlpaw.Tagpaw.Boldpaw.PreCode
Covered APIs
涵盖 API
API
接口
Description
说明
Ui
The minimal render contract used throughout Paw.
Paw 全局通用的最小渲染契约。
List
Renders multiple Ui values in order.
按顺序渲染多个 Ui 值。
Html
Writes trusted raw HTML without escaping.
直接输出可信的原始 HTML,不做转义。
Tag
Builds escaped tags when Paw does not already have a dedicated component.
当 Paw 没有现成组件时,用它构造带转义的 HTML 标签。
String, StringNoWrap, Bold
Escaped text helpers for default text, no-wrap text, and strong emphasis.
用于普通文本、不换行文本和强调文本的转义辅助类型。
P, Small, Pre, PreCode
Paragraph and code-oriented helpers.
面向段落和代码展示的辅助类型。
Br, Hr, Vr
Line, horizontal, and vertical separators.
换行、水平分隔线和垂直分隔元素。
H1, H2, H3, Heading
Heading helpers for quick text or custom heading bodies.
用于快速标题文本或自定义标题内容的辅助类型。
Minimal Example: Compose escaped content first
最小示例:优先组合可转义内容

Default to escaped primitives and only use Html when the content is fully trusted.

默认优先使用会转义的原语,只有内容完全可信时才使用 Html。
Primitive composition
原语组合

Use escaped text by default, then layer formatting with higher-level helpers.

默认先使用会转义的文本,再逐步叠加更高层的格式化辅助类型。

Small and StringNoWrap are useful inside dense layouts such as tables.

Small 和 StringNoWrap 很适合用在表格这类紧凑布局里。

paw.P{paw.String("safe text"), paw.Bold("important")}

body := paw.List{
	paw.H2("Primitive composition"),
	paw.P{
		paw.String("Use "),
		paw.Bold("escaped text"),
		paw.String(" by default."),
	},
	paw.PreCode{
		Language: "go",
		Code:     "fmt.Println(\"hello\")",
	},
}
Advanced Example: Use Tag and Html deliberately
进阶示例:有意识地使用 Tag 和 Html

Tag keeps escaping on attribute names and values. Html skips escaping completely and should be reserved for trusted markup.

Tag 会继续对属性名和值做转义;Html 则完全跳过转义,因此只应保留给可信标记。
Tag
Trusted raw HTML

StringNoWrap keeps short identifiers together in tight layouts.
StringNoWrap 可以让短标识符在紧凑布局中保持不换行。

paw.Tag{
	Name: "div",
	Attr: map[string]string{"class": "d-flex align-items-center"},
	Body: paw.List{
		paw.Badge{Text: "Tag", Color: paw.ColorPrimary},
		paw.Vr{},
		paw.Html(`<span class="text-success">Trusted raw HTML</span>`),
	},
}
Notes and Related Docs
说明与相关文档

Notes

说明

Html does no escaping at all. Only pass trusted markup.

Html 完全不做转义,只能传入可信标记。

Tag is the preferred escape hatch when you just need one HTML element and still want escaped attributes and body content.

如果你只需要一个 HTML 元素,同时还希望属性和值继续被转义,Tag 是首选的 escape hatch。

Related Pages

相关页面
Layout and Navigation
布局与导航
Compose responsive layouts, links, navigation, and progressive disclosure patterns.
组合响应式布局、链接、导航以及渐进展示类交互。
Tables
表格
Render compact or rich tables and override individual cells when needed.
渲染紧凑或富信息表格,并在需要时覆盖单元格行为。
Source and References
源码与参考资料