Skip to content

Commit 94b6f77

Browse files
committed
add ToC & max clause depth to provide flexibility
Ecma house style is a ToC 3 deep and max clauses 6, but there may be scenarios where a TC wants to generate a draft with fewer or more in the context of their specific standard
1 parent 44d8f38 commit 94b6f77

File tree

6 files changed

+18
-6
lines changed

6 files changed

+18
-6
lines changed

spec/index.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,8 @@ <h1>Options</h1>
5555
<tr><td>`--assets-dir`</td><td>`assetsDir`</td><td>Directory in which to place assets when using `--assets=external`. Defaults to "assets".</td></tr>
5656
<tr><td>`--lint-spec`</td><td>`lintSpec`</td><td>Enforce some style and correctness checks.</td></tr>
5757
<tr><td>`--error-formatter`</td><td></td><td>The <a href="https://eslint.org/docs/user-guide/formatters/">eslint formatter</a> to be used for printing warnings and errors when using `--verbose`. Either the name of a built-in eslint formatter or the package name of an installed eslint compatible formatter.</td></tr>
58-
<tr><td>`--max-clause-depth N`</td><td></td><td>Warn when clauses exceed a nesting depth of N, and cause those clauses to be numbered by incrementing their parent clause's number rather than by nesting a new number within their parent clause.</td></tr>
58+
<tr><td>`--max-clause-depth N`</td><td>`maxClauseDepth`</td><td>Warn when clauses exceed a nesting depth of N, and cause those clauses to be numbered by incrementing their parent clause's number rather than by nesting a new number within their parent clause. Default 6.</td></tr>
59+
<tr><td>`--toc-depth N`</td><td>`tocDepth`</td><td>Maximum level of subclause to be emitted in table of contents. Default 3.</td></tr>
5960
<tr><td>`--strict`</td><td></td><td>Exit with an error if there are warnings. Cannot be used with `--watch`.</td></tr>
6061
<tr><td>`--multipage`</td><td></td><td>Emit a distinct page for each top-level clause.</td></tr>
6162
</table>

src/Spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -647,7 +647,7 @@ export default class Spec {
647647

648648
if (this.opts.printable) {
649649
// Ecma guidance directs three levels of clause in ToC
650-
new Toc(this).build(3);
650+
new Toc(this).build(this.opts.tocDepth ?? 3);
651651
} else {
652652
({ js: tocJs, eles: commonEles } = makeMenu(this));
653653
}

src/args.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,13 @@ export const options = [
7171
name: 'max-clause-depth',
7272
type: Number,
7373
description:
74-
'The maximum nesting depth for clauses; exceeding this will cause a warning. Defaults to no limit.',
74+
'The maximum nesting depth for clauses; exceeding this will cause a warning. Defaults to six (per Ecma house style.)',
75+
},
76+
{
77+
name: 'toc-depth',
78+
type: Number,
79+
description:
80+
'The maximum depth for listing clauses in print table of contents. Defaults to three (per Ecma house style.)',
7581
},
7682
{
7783
name: 'multipage',

src/clauseNums.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ export default function iterator(spec: Spec): ClauseNumberIterator {
1010
let inAnnex = false;
1111
let currentLevel = 0;
1212
let hasWarnedForExcessNesting = false;
13-
const MAX_LEVELS = spec.opts.maxClauseDepth ?? Infinity;
13+
// Ecma house style calls for a maximum of 5 levels of clause division
14+
const MAX_LEVELS = spec.opts.maxClauseDepth ?? 6;
1415

1516
return {
1617
next(clauseStack: Clause[], node: HTMLElement) {
@@ -32,12 +33,12 @@ export default function iterator(spec: Spec): ClauseNumberIterator {
3233
message: 'clause is being numbered without numbering its parent clause',
3334
});
3435
}
35-
if (!hasWarnedForExcessNesting && level + 1 > (spec.opts.maxClauseDepth ?? Infinity)) {
36+
if (!hasWarnedForExcessNesting && level + 1 > (spec.opts.maxClauseDepth ?? 6)) {
3637
spec.warn({
3738
type: 'node',
3839
node,
3940
ruleId: 'max-clause-depth',
40-
message: `clause exceeds maximum nesting depth of ${spec.opts.maxClauseDepth}`,
41+
message: `clause exceeds maximum nesting depth of ${spec.opts.maxClauseDepth ?? 'six'}`,
4142
});
4243
hasWarnedForExcessNesting = true;
4344
}

src/cli.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,9 @@ const build = debounce(async function build() {
116116
if (args['max-clause-depth']) {
117117
opts.maxClauseDepth = args['max-clause-depth'];
118118
}
119+
if (args['toc-depth']) {
120+
opts.tocDepth = args['toc-depth'];
121+
}
119122
if (args['no-toc'] != null) {
120123
opts.toc = !args['no-toc'];
121124
}

src/ecmarkup.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ export interface Options {
3333
date?: Date;
3434
location?: string;
3535
maxClauseDepth?: number;
36+
tocDepth?: number;
3637
multipage?: boolean;
3738
extraBiblios?: ExportedBiblio[];
3839
contributors?: string;

0 commit comments

Comments
 (0)