rusdox 1.0.0

Generate DOCX and PDF from YAML at Rust speed.
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
# YAML Guide

RusDox is designed so the YAML reads like the document.

The basic shape is always:

```yaml
version: 1
output_name: my-document
blocks:
  - type: title
    text: My Document
  - type: body
    text: This is a paragraph.
```

## Top-Level Fields

version

- Required for new files
- Current value: 1
- Use rusdox migrate legacy.yaml --in-place for legacy unversioned files

`output_name`

- Optional
- Controls the file name of the generated output
- If omitted, RusDox uses the spec file stem

`metadata`

- Optional
- Controls DOCX package properties such as title, author, subject, keywords, and custom properties

`blocks`

- Required for real documents
- Ordered from top to bottom
- This is the document structure

`styles`

- Optional
- Defines reusable named paragraph, run, and table styles
- Supports inheritance through `based_on`
- Paragraph styles can also set `next`

`variables`

- Optional
- Defines reusable values for nested interpolation, repeat blocks, and bounded conditions

## Metadata

Use metadata when generated documents need clean properties in Word, search tools, or downstream automation.

```yaml
metadata:
  title: Client Rollout Plan
  author: RusDox Studio
  subject: Q4 regional rollout
  language: en-US
  keywords:
    - rollout
    - planning
  custom_properties:
    Client: Northwind Health
    Sponsor: Maya Chen
```

Supported metadata fields:

- `title`
- `author`
- `subject`
- `language`: a BCP 47-style document language such as `en-US`, `fr`, or `mul`
- `keywords`
- `custom_properties`

`custom_properties` values are stored as string custom properties in the DOCX package.

## Variables, Includes, And Repeaters

Use these features when one YAML file would otherwise become repetitive.

Variables use `{{name}}` placeholders:

```yaml
variables:
  client: Northwind Health
  quarter: Q4 2026

blocks:
  - type: title
    text: "{{client}} Rollout Plan"
  - type: subtitle
    text: "{{quarter}} program snapshot"
```

Includes inline reusable block fragments relative to the current YAML file:

```yaml
blocks:
  - type: include
    path: fragments/summary.yaml
    variables:
      sponsor: Maya Chen
```

An included YAML fragment can be:

- a single block mapping
- a sequence of blocks
- a mapping with optional `variables` plus `blocks`

Repeaters expand a block template for each item in a sequence:

```yaml
variables:
  regions:
    - name: North America
      owner: Maya
    - name: EMEA
      owner: Leon

blocks:
  - type: repeat
    variable: regions
    as: region
    blocks:
      - type: section
        text: "{{region.name}}"
      - type: body
        text: "Owner: {{region.owner}}"
```

Supported repeat fields:

- `variable`: name of a sequence variable to iterate
- `items`: inline sequence to iterate
- `as`: loop variable name, defaults to `item`
- `blocks`: template block list

Each repeat iteration also exposes:

- `repeat_index`: zero-based index
- `repeat_number`: one-based index

## Conditions, filters, and escaping

Use a bounded when block for truthiness or exact scalar equality:

    variables:
      customer:
        active: true
    blocks:
      - type: when
        path: customer.active
        equals: true
        blocks:
          - type: body
            text: Active customer
        otherwise:
          - type: body
            text: Inactive customer

Expressions support nested mapping/array paths and exactly five deterministic
filters: upper, lower, title, trim, and default("text").

    text: "{{ customer.name | trim | title }}"
    text: "{{ customer.owner | default(\"unassigned\") | upper }}"

Write four opening braces and four closing braces for literal double braces.
Expression values always become document text; they cannot inject raw OOXML or
execute code. The same expression behavior is available to JSON and TOML specs.
See [Spec Versioning and Authoring Tools](spec-versioning.md).

## Named Styles

Use named styles when the document needs stable reusable formatting instead of repeating direct properties on every block.

Example:

```yaml
styles:
  paragraph:
    - id: lead
      based_on: Normal
      next: body
      paragraph:
        alignment: center
        spacing_after: 180
        keep_next: true
      run:
        bold: true
        color: "0F172A"
        font_family: Georgia
        font_size: 28
  run:
    - id: accent
      based_on: DefaultParagraphFont
      properties:
        italic: true
        color: "AA5500"
  table:
    - id: grid
      based_on: TableNormal
      properties:
        width: 9360

blocks:
  - type: paragraph
    spec:
      style_id: lead
      runs:
        - text: Styled
        - text: " emphasis"
          style_id: accent
  - type: table
    spec:
      style_id: grid
      columns:
        - label: Metric
          width: 4680
      rows:
        - cells:
            - kind: text
              text: ARR
```

Style definition groups:

- `styles.paragraph`
- `styles.run`
- `styles.table`

Paragraph style fields:

- `id`
- `name`
- `based_on`
- `next`
- `paragraph.list`
- `paragraph.alignment`
- `paragraph.spacing_before`
- `paragraph.spacing_after`
- `paragraph.keep_next`
- `paragraph.page_break_before`
- `run.bold`
- `run.italic`
- `run.underline`
- `run.strikethrough`
- `run.small_caps`
- `run.shadow`
- `run.color`
- `run.font_family`
- `run.font_size`
- `run.vertical_align`

Run style fields:

- `id`
- `name`
- `based_on`
- `properties.bold`
- `properties.italic`
- `properties.underline`
- `properties.strikethrough`
- `properties.small_caps`
- `properties.shadow`
- `properties.color`
- `properties.font_family`
- `properties.font_size`
- `properties.vertical_align`

Table style fields:

- `id`
- `name`
- `based_on`
- `properties.width`
- `properties.borders`

Units:

- paragraph spacing and table widths use twips
- run `font_size` uses OOXML half-points, so `24` means `12pt`

## Simple Block Types

Use these when you want readable documents with strong defaults:

- `cover_title`
- `title`
- `subtitle`
- `hero`
- `centered_note`
- `page_heading`
- `section`
- `body`
- `tagline`
- `image`
- `logo`
- `signature`
- `chart`
- `spacer`

Example:

```yaml
blocks:
  - type: cover_title
    text: Board Report
  - type: subtitle
    text: March 2026
  - type: hero
    text: Prepared automatically with RusDox
  - type: centered_note
    text: Internal use only
  - type: page_heading
    text: Board Narrative
  - type: body
    text: Revenue expanded faster than forecast.
```

`page_heading` starts a new page before the heading.

`spacer` adds vertical space when you want breathing room between sections.

## Visual Blocks

Use visual blocks when the document needs brand marks, screenshots, signatures, or SVG charts.

Example:

```yaml
- type: logo
  path: ../assets/rusdox-mark.svg
  alt_text: RusDox logo
  max_width_twips: 2200

- type: image
  path: ../assets/template-gallery.png
  alt_text: RusDox template gallery
  max_width_twips: 7200

- type: chart
  path: ../assets/benchmark-stress-1000-pages.svg
  alt_text: RusDox benchmark chart
  max_width_twips: 7200

- type: signature
  path: ../assets/signature-demo.svg
  alt_text: Automated approval signature
  max_width_twips: 2800
```

Supported visual fields:

- `path`
- `alt_text`
- `alignment`: `left`, `center`, `right`, `justified`
- `width_twips`
- `height_twips`
- `max_width_twips`
- `max_height_twips`

Supported file formats:

- PNG
- JPEG
- SVG

`alt_text` is required and must be meaningful. It is preserved in the DOCX
drawing properties and checked against the PDF semantic projection; a file name
or blank string does not satisfy validation. See the
[international and accessibility contract](international-accessibility.md).

## List Blocks

### `bullets`

```yaml
- type: bullets
  items:
    - Confirm launch date
    - Finalize sales enablement
    - Publish support macros
```

### `label_values`

Good for notes, metadata, meeting headers, and document summaries.

```yaml
- type: label_values
  items:
    - label: Date
      value: 2026-03-10
    - label: Owner
      value: Operations
```

### `metrics`

Good for dashboard-style cards.

Available tones:

- `positive`
- `neutral`
- `warning`
- `risk`

```yaml
- type: metrics
  items:
    - label: ARR
      value: $18.7M
      tone: positive
    - label: Cash Runway
      value: 24 mo
      tone: warning
```

## Tables

Tables use explicit columns and rows.

Each column needs:

- `label`
- `width`

Each row has `cells`.

Each cell can be:

- `kind: text`
- `kind: status`

Example:

```yaml
- type: table
  spec:
    style_id: grid
    columns:
      - label: Category
        width: 2800
      - label: Current
        width: 2000
      - label: Status
        width: 1600
    rows:
      - cells:
          - kind: text
            text: ARR
          - kind: text
            text: $18.7M
          - kind: status
            text: Strong
            tone: positive
```

`width` values are DOCX table widths in twips.

You usually only need to copy a working table from an example and edit the content.

## Custom Paragraphs

Use `paragraph` when you need mixed formatting inside one paragraph.

Example:

```yaml
- type: paragraph
  spec:
    alignment: center
    spacing_after_twips: 120
    runs:
      - text: "This is "
      - text: important
        bold: true
      - text: " and "
      - text: styled
        italic: true
        color: D00000
```

Supported paragraph fields:

- `runs`
- `style_id`
- `alignment`: `left`, `center`, `right`, `justified`
- `spacing_before_twips`
- `spacing_after_twips`
- `page_break_before`
- `section_break_before`

Supported run fields:

- `text`
- `style_id`
- `bold`
- `italic`
- `underline`
- `strikethrough`
- `small_caps`
- `shadow`
- `color`
- `font_family`
- `size_pt`
- `vertical_align`
- `hyperlink`: `https://`, `http://`, `mailto:`, or `#bookmark`
- `bookmark`: 1–40 ASCII letters, digits, or underscores
- `field`: currently `table_of_contents`
- `footnote`

Underline values:

- `single`
- `double`
- `dotted`
- `dash`
- `wavy`
- `words`
- `none`

Vertical align values:

- `superscript`
- `subscript`
- `baseline`

## Shared Page Controls And Semantic Blocks

`page_setup`, `header`, `footer`, and `page_numbering` are consumed by both DOCX and PDF. Orientation is explicit and must agree with width and height.

```yaml
page_setup:
  width_twips: 15840
  height_twips: 12240
  orientation: landscape
  margin_top_twips: 1080
  margin_right_twips: 900
  margin_bottom_twips: 1080
  margin_left_twips: 900
header:
  text: Quarterly review
  alignment: right
footer:
  text: Page {page} of {pages}
  alignment: center
page_numbering:
  start_at: 3
  format: lower_roman
blocks:
  - type: table_of_contents
    title: Contents
  - type: page_break
  - type: section_break
```

The DOCX TOC is an updateable Word field. PDF emits the heading list known from the spec at render time and does not invent page numbers.

## Rich Table Rows And Cells

Rows accept `repeat_as_header` and `allow_split_across_pages`. A `kind: rich` cell accepts `paragraphs`, horizontal `grid_span`, `background_color`, and an optional `nested_table`. See [`dual_output_contract.yaml`](../examples/dual_output_contract.yaml) for a complete, parity-tested example.

## Best Practices

- Use variables for repeated values, not for every sentence in the document.
- Reach for `include` and `repeat` before moving to Rust if the workflow is still mostly static content.
- Prefer `title`, `section`, `body`, `bullets`, `metrics`, and `table` before reaching for custom paragraphs.
- Let config control styling instead of repeating style values everywhere.
- Copy a close example and edit the content.

## See Real Files

- [../examples/board_report.yaml]../examples/board_report.yaml
- [../examples/executive_dashboard.yaml]../examples/executive_dashboard.yaml
- [../examples/dual_output_contract.yaml]../examples/dual_output_contract.yaml
- [../examples/international_scripts.yaml]../examples/international_scripts.yaml
- [../examples/formatting_showcase.yaml]../examples/formatting_showcase.yaml
- [../examples/named_styles_showcase.yaml]../examples/named_styles_showcase.yaml
- [../examples/yaml_composition_showcase.yaml]../examples/yaml_composition_showcase.yaml