Attributes are key-value pairs that configure elements and provide metadata.
Syntax
Attribute syntax uses key-value pairs separated by semicolons and/or newlines:
(
key1: value1;
key2: value2
key3: value3
)
Data Types
Attributes can have different data types that define what values they can contain and how they are validated. Chalk supports both built-in primitive data types and custom data types defined in your library.
Primitive Types
string: Text values (no quotes needed)number: Numeric values, including decimalsboolean: True/false values (accepts:true/false,yes/no,1/0)string-list: Comma-separated stringsnumber-list: Comma-separated numbersformatted-string: Text with markdown formatting support
Examples
element(
title: My Title
count: 42
enabled: true
tags: javascript,react,frontend
description: This supports **bold** and *italic* text
)
Custom Types
Libraries can define custom attribute types with validation:
const dateType = {
identifier: 'date',
validate: (value) => /^\d{4}-\d{2}-\d{2}$/.test(value)
};
Attribute Validation
- Required vs Optional: Attributes can be marked as required or optional
- Default Values: Optional attributes can have default values
- Type Validation: Values are validated against their declared types
Next Steps
- Language Guide - Back to language guide index
- Elements Reference - Learn about different element types
- Formatting Guide - Inline text formatting
- Primitives Guide - Built-in elements and formatting
- Language Overview - File types and basic syntax
- API Documentation - How to define attributes in libraries
- Home - Back to documentation home