- Overview - Back to language guide index
- Elements - Building blocks of .chalk documents
- Formatting - Inline text formatting syntax
- Style Guide - Best practices and conventions
Attributes
Attributes are key-value pairs that configure elements and provide metadata. They are defined within parentheses (...) as a section of standard-syntax elements, containers, meta-elements, and headers.
Table of Contents
Syntax
Attribute syntax uses key-value pairs separated by semicolons and/or newlines:
(
key1: value1
key2: value2
key3: value3
)
(key1: value1; key2: value2)
(
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.
See the Primitives Reference for complete details on each type.
Examples
element(
// String attribute
title: My Title
// Number attribute
count: 42
// Boolean attribute - explicit values
enabled: true
disabled: false
// Boolean attribute - shorthand (identifier means true)
interactive
visible
// Boolean attribute - negation (!identifier means false)
!hidden
!collapsed
// String list attribute
tags: javascript, react, frontend
// Formatted string attribute
description: This supports **bold** and *italic* text
// Email attribute
contact: user@example.com
// Date attribute
published: 2024-12-19
// URL attribute
link: https://example.com/page
// RGB colour attribute
colour: #ff5733
)
Attribute Validation
- Required vs Optional: Attributes can be marked as required or optional in library definitions. A compiler error occurs if a required attribute is missing.
- Default Values: Optional attributes can be given default values.
- Type Validation: Values are validated against their declared types.