Version 0.0.10
Ordered Lists & Hierarchical Numbering
Updated 5 min ago
Configuring multi-level numbering schemas, hierarchical decimals, and indentation.
In Microsoft Word, numbered lists are defined through document-level abstract numbering schemes. @m2d/list connects Markdown ordered lists (ol) to Word OpenXML numbering configurations, providing clean hierarchical numbering out of the box.
Default Hierarchical Decimal Numbering
By default, @m2d/list structures nested ordered lists into hierarchical legal/technical style numbers:
- Level 1:
1.- Level 2:
1.1.- Level 3:
1.1.1.- Level 4:
1.1.1.1.- Level 5:
A. - Level 6:
a. - Level 7:
i. - Level 8:
I.
- Level 5:
- Level 4:
- Level 3:
- Level 2:
This prevents nested lists in complex reports from resetting ambiguously to 1. at every sub-level.
Custom Numbering Schemes with createLevels
You can customize the numbering formats, base indentation, and indentation increments per level using the exported createLevels helper:
import { createLevels, listPlugin } from "@m2d/list";
import { LevelFormat } from "docx";
// Define a custom outline numbering hierarchy: A. -> 1. -> a. -> i.
const customLevels = createLevels(
[
LevelFormat.UPPER_LETTER, // Level 1: A.
LevelFormat.DECIMAL, // Level 2: 1.
LevelFormat.LOWER_LETTER, // Level 3: a.
LevelFormat.LOWER_ROMAN, // Level 4: i.
],
0.5, // Base indentation for first level in inches (default: 0.4)
0.3 // Additional indentation added per level in inches (default: 0.25)
);
const plugin = listPlugin({
levels: customLevels,
});How Word OpenXML Numbering Works
When compiling to DOCX:
listPlugingenerates a unique UUID-based numbering reference (numReference).- In the
rootlifecycle hook, it registers this numbering definition indocProps.numbering.config. - In the
blockhook, each list item paragraph receives the matchingnumberingproperty with its computed depthlevel. - This ensures that Microsoft Word renders native list numbers that update dynamically if items are added or rearranged by Word users.