trim
Type: string
Signature: md.string().trim()
What It Is
On this page, md.string().trim() centers on document-level structure checks, explicit section targeting, and typed field extraction to keep trim parsing deterministic and schema-driven. The example expects 1 h1 heading, 1 h2 section, and list content and returns top-level keys meta directly from the declared trim extraction rules. Violations produce issue codes like missing_section, which avoids brittle string checks and keeps trim failure handling explicit.
When to Use
Apply md.string().trim() when your document flow requires typed markdown parsing with deterministic contracts for trim and strict schema adherence over permissive parsing. It is less suitable for exploratory drafts that intentionally avoid strict validation under trim, because teams must accept key-level strictness that improves typing but rejects ad-hoc variations. Use document(), section(), fields(), and string() around md.string().trim() to keep trim contracts transparent and reduce ambiguity in validation behavior.
md.string().trim()
Input Markdown
## 1. META
- Team: Risk PlatformSchema
import { md } from '@markschema/mdshape'
const schema = md.document({
meta: md.section('1. META').fields({
Team: md.string().trim(),
}),
})Result
Success
{
"success": true,
"data": {
"meta": {
"Team": "Risk Platform"
}
}
}Error
Failure trigger: The input violates one or more constraints declared in the schema; use issues[].path and issues[].code to locate the exact failing node.
{
"success": false,
"error": {
"issues": [
{
"code": "missing_section",
"message": "Missing section \"1. META\"",
"path": [
"meta"
],
"line": 1,
"position": {
"start": {
"line": 1,
"column": 1
}
}
}
]
}
}