docs: explain legal style numbering, for 1.1 under a level in Chinese counting (#3857)

A level's text shows each level's number in that level's format, so
"%1.%2" under a level in Chinese counting is 一.1 (#3425).
isLegalNumberingStyle writes w:isLgl, which makes every number in the
text a decimal number, as Word's Legal style numbering does, but the
docs never mentioned it and its TSDoc only said "legal numbering style
(e.g., 1.1.1)".


Claude-Session: https://claude.ai/code/session_01X5zGDL3sgGVBMXPfny376c

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Dolan
2026-10-28 13:58:35 +00:00
committed by GitHub
co-authored by Claude Opus 5.5
parent 1146a21edd
commit 2f82dcb464
2 changed files with 56 additions and 10 deletions
+49 -7
View File
@@ -35,13 +35,14 @@ Each `config` entry includes the following properties:
Levels define the numbering definition itself, what it looks like, the indention, the alignment and the style. The reason why it is an array is because it allows the ability to create sub-lists. A sub list will have a different configuration because you may want the sub-list to have a different indentation or different bullet.
| Property | Type | Notes | Possible Values |
| --------- | ------------- | -------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| level | `number` | Required | The list level this definition is for. `0` is for the root level, `1` is for a sub list, `2` is for a sub-sub-list etc. |
| format | `LevelFormat` | Optional | `DECIMAL`, `UPPER_ROMAN`, `LOWER_ROMAN`, `UPPER_LETTER`, `LOWER_LETTER`, `ORDINAL`, `CARDINAL_TEXT`, `ORDINAL_TEXT`, `HEX`, `CHICAGO`, `IDEOGRAPH__DIGITAL`, `JAPANESE_COUNTING`, `AIUEO`, `IROHA`, `DECIMAL_FULL_WIDTH`, `DECIMAL_HALF_WIDTH`, `JAPANESE_LEGAL`, `JAPANESE_DIGITAL_TEN_THOUSAND`, `DECIMAL_ENCLOSED_CIRCLE`, `DECIMAL_FULL_WIDTH2`, `AIUEO_FULL_WIDTH`, `IROHA_FULL_WIDTH`, `DECIMAL_ZERO`, `BULLET`, `GANADA`, `CHOSUNG`, `DECIMAL_ENCLOSED_FULLSTOP`, `DECIMAL_ENCLOSED_PARENTHESES`, `DECIMAL_ENCLOSED_CIRCLE_CHINESE`, `IDEOGRAPH_ENCLOSED_CIRCLE`, `IDEOGRAPH_TRADITIONAL`, `IDEOGRAPH_ZODIAC`, `IDEOGRAPH_ZODIAC_TRADITIONAL`, `TAIWANESE_COUNTING`, `IDEOGRAPH_LEGAL_TRADITIONAL`, `TAIWANESE_COUNTING_THOUSAND`, `TAIWANESE_DIGITAL`, `CHINESE_COUNTING`, `CHINESE_LEGAL_SIMPLIFIED`, `CHINESE_COUNTING_THOUSAND`, `KOREAN_DIGITAL`, `KOREAN_COUNTING`, `KOREAN_LEGAL`, `KOREAN_DIGITAL2`, `VIETNAMESE_COUNTING`, `RUSSIAN_LOWER`, `RUSSIAN_UPPER`, `NONE`, `NUMBER_IN_DASH`, `HEBREW1`, `HEBREW2`, `ARABIC_ALPHA`, `ARABIC_ABJAD`, `HINDI_VOWELS`, `HINDI_CONSONANTS`, `HINDI_NUMBERS`, `HINDI_COUNTING`, `THAI_LETTERS`, `THAI_NUMBERS`, `THAI_COUNTING`, `BAHT_TEXT`, `DOLLAR_TEXT`, `CUSTOM` |
| text | `string` | Optional | A unique `string` to describe the shape of the bullet |
| alignment | `string` | Required | `START`, `CENTER`, `END`, `BOTH`, `MEDIUM_KASHIDA`, `DISTRIBUTE`, `NUM_TAB`, `HIGH_KASHIDA`, `LOW_KASHIDA`, `THAI_DISTRIBUTE`, `LEFT`, `RIGHT`, `JUSTIFIED` |
| style | `object` | Optional | An object containing `run`, `paragraph`, and `style` sub-properties (see below) |
| Property | Type | Notes | Possible Values |
| --------------------- | ------------- | -------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| level | `number` | Required | The list level this definition is for. `0` is for the root level, `1` is for a sub list, `2` is for a sub-sub-list etc. |
| format | `LevelFormat` | Optional | `DECIMAL`, `UPPER_ROMAN`, `LOWER_ROMAN`, `UPPER_LETTER`, `LOWER_LETTER`, `ORDINAL`, `CARDINAL_TEXT`, `ORDINAL_TEXT`, `HEX`, `CHICAGO`, `IDEOGRAPH__DIGITAL`, `JAPANESE_COUNTING`, `AIUEO`, `IROHA`, `DECIMAL_FULL_WIDTH`, `DECIMAL_HALF_WIDTH`, `JAPANESE_LEGAL`, `JAPANESE_DIGITAL_TEN_THOUSAND`, `DECIMAL_ENCLOSED_CIRCLE`, `DECIMAL_FULL_WIDTH2`, `AIUEO_FULL_WIDTH`, `IROHA_FULL_WIDTH`, `DECIMAL_ZERO`, `BULLET`, `GANADA`, `CHOSUNG`, `DECIMAL_ENCLOSED_FULLSTOP`, `DECIMAL_ENCLOSED_PARENTHESES`, `DECIMAL_ENCLOSED_CIRCLE_CHINESE`, `IDEOGRAPH_ENCLOSED_CIRCLE`, `IDEOGRAPH_TRADITIONAL`, `IDEOGRAPH_ZODIAC`, `IDEOGRAPH_ZODIAC_TRADITIONAL`, `TAIWANESE_COUNTING`, `IDEOGRAPH_LEGAL_TRADITIONAL`, `TAIWANESE_COUNTING_THOUSAND`, `TAIWANESE_DIGITAL`, `CHINESE_COUNTING`, `CHINESE_LEGAL_SIMPLIFIED`, `CHINESE_COUNTING_THOUSAND`, `KOREAN_DIGITAL`, `KOREAN_COUNTING`, `KOREAN_LEGAL`, `KOREAN_DIGITAL2`, `VIETNAMESE_COUNTING`, `RUSSIAN_LOWER`, `RUSSIAN_UPPER`, `NONE`, `NUMBER_IN_DASH`, `HEBREW1`, `HEBREW2`, `ARABIC_ALPHA`, `ARABIC_ABJAD`, `HINDI_VOWELS`, `HINDI_CONSONANTS`, `HINDI_NUMBERS`, `HINDI_COUNTING`, `THAI_LETTERS`, `THAI_NUMBERS`, `THAI_COUNTING`, `BAHT_TEXT`, `DOLLAR_TEXT`, `CUSTOM` |
| text | `string` | Optional | A unique `string` to describe the shape of the bullet |
| alignment | `string` | Required | `START`, `CENTER`, `END`, `BOTH`, `MEDIUM_KASHIDA`, `DISTRIBUTE`, `NUM_TAB`, `HIGH_KASHIDA`, `LOW_KASHIDA`, `THAI_DISTRIBUTE`, `LEFT`, `RIGHT`, `JUSTIFIED` |
| isLegalNumberingStyle | `boolean` | Optional | Whether every number in the level's `text`, the levels above's too, is a decimal number. See [Legal style numbering](#legal-style-numbering) |
| style | `object` | Optional | An object containing `run`, `paragraph`, and `style` sub-properties (see below) |
#### Style sub-properties
@@ -156,6 +157,47 @@ const doc = new Document({
What a level's `run` doesn't set, Word takes from the paragraph's mark, which a `Paragraph`'s `run` option formats, and not from the paragraph's text. So in a paragraph whose `TextRun`s have a bigger `size`, the number stays the size of the paragraph's style, unless the level sets a `size`, or the paragraph has the same `run: { size }` as its text.
### Legal style numbering
A level's `text` can show the numbers of the levels above it, such as `"%1.%2"`, and each is written in its own level's `format`. So under a level in Chinese counting (一、二、), a level whose `text` is `"%1.%2"` is numbered 一.1. With `isLegalNumberingStyle: true`, a level writes every number in its `text` as a decimal number, as Word's **Legal style numbering** does, so it's numbered 1.1:
```ts live
import { AlignmentType, Document, LevelFormat, Paragraph } from "docx";
const doc = new Document({
numbering: {
config: [
{
reference: "chapters",
levels: [
{ level: 0, format: LevelFormat.CHINESE_COUNTING, text: "%1、", alignment: AlignmentType.START },
{
level: 1,
format: LevelFormat.DECIMAL,
text: "%1.%2",
alignment: AlignmentType.START,
// 1.1, 1.2 and 2.1, not 一.1, 一.2 and 二.1
isLegalNumberingStyle: true,
style: { paragraph: { indent: { left: 720, hanging: 720 } } },
},
],
},
],
},
sections: [
{
children: [
new Paragraph({ text: "General provisions", numbering: { reference: "chapters", level: 0 } }),
new Paragraph({ text: "Scope", numbering: { reference: "chapters", level: 1 } }),
new Paragraph({ text: "Definitions", numbering: { reference: "chapters", level: 1 } }),
new Paragraph({ text: "Obligations", numbering: { reference: "chapters", level: 0 } }),
new Paragraph({ text: "Payment", numbering: { reference: "chapters", level: 1 } }),
],
},
],
});
```
### Lists that bring their own definition
A paragraph's `numbering` can give its list's definition, its `reference` and its `levels`, rather than the reference of one in the document's `numbering` option. The definition is added to the document's numbering when the paragraph is written, unless the document already has a list with its reference. It is how content made before the document it goes in, such as by a function that returns paragraphs, brings its lists with it.
+7 -3
View File
@@ -282,7 +282,7 @@ export const LevelSuffix = {
* @property alignment - Text alignment for the numbering
* @property start - Starting number for this level
* @property suffix - Character(s) following the numbering (tab, space, nothing)
* @property isLegalNumberingStyle - Use legal numbering style
* @property isLegalNumberingStyle - Write every number in the level's text as a decimal number
* @property style - Run and paragraph style properties
*/
export type ILevelsOptions = {
@@ -301,7 +301,10 @@ export type ILevelsOptions = {
readonly start?: number;
/** Character(s) following the numbering. */
readonly suffix?: (typeof LevelSuffix)[keyof typeof LevelSuffix];
/** Use legal numbering style (e.g., 1.1.1). */
/**
* Writes every number in the level's `text`, the levels above's too, as a decimal number, as Word's Legal style
* numbering does. Under a level in Chinese counting, `"%1.%2"` is then 1.1 rather than 一.1.
*/
readonly isLegalNumberingStyle?: boolean;
/** Run and paragraph style properties. */
readonly style?: {
@@ -340,7 +343,8 @@ class Suffix extends XmlComponent {
/**
* Legal numbering style flag.
*
* When enabled, creates multi-level legal numbering like 1.1.1.
* When enabled, every number in the level's text is a decimal number, whatever its own level's format, such as 1.1
* rather than 一.1.
*
* Reference: http://officeopenxml.com/WPnumbering-isLgl.php
*/