diff --git a/spec/index.html b/spec/index.html index 36df617a..4a5505e4 100644 --- a/spec/index.html +++ b/spec/index.html @@ -55,7 +55,8 @@

Options

`--assets-dir``assetsDir`Directory in which to place assets when using `--assets=external`. Defaults to "assets". `--lint-spec``lintSpec`Enforce some style and correctness checks. `--error-formatter`The eslint formatter 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. - `--max-clause-depth N`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. + `--max-clause-depth N``maxClauseDepth`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 5. + `--printed-toc-depth N``printedTocDepth`Maximum level of subclause to be emitted in printed table of contents. Default 3. (ignored if `--printable` option omitted) `--strict`Exit with an error if there are warnings. Cannot be used with `--watch`. `--multipage`Emit a distinct page for each top-level clause. diff --git a/src/Spec.ts b/src/Spec.ts index 52de1f36..bc6557a5 100644 --- a/src/Spec.ts +++ b/src/Spec.ts @@ -647,7 +647,7 @@ export default class Spec { if (this.opts.printable) { // Ecma guidance directs three levels of clause in ToC - new Toc(this).build(3); + new Toc(this).build(this.opts.tocDepth ?? 3); } else { ({ js: tocJs, eles: commonEles } = makeMenu(this)); } diff --git a/src/args.ts b/src/args.ts index 9c4453cc..88cd7cd1 100644 --- a/src/args.ts +++ b/src/args.ts @@ -71,7 +71,13 @@ export const options = [ name: 'max-clause-depth', type: Number, description: - 'The maximum nesting depth for clauses; exceeding this will cause a warning. Defaults to no limit.', + 'The maximum nesting depth for clauses; exceeding this will cause a warning. Defaults to five (per Ecma house style.)', + }, + { + name: 'printed-toc-depth', + type: Number, + description: + 'Maximum level of subclause to be emitted in printed table of contents. Default 3. (ignored if `--printable` option omitted)', }, { name: 'multipage', diff --git a/src/clauseNums.ts b/src/clauseNums.ts index 143a6c06..cb477ca2 100644 --- a/src/clauseNums.ts +++ b/src/clauseNums.ts @@ -10,7 +10,8 @@ export default function iterator(spec: Spec): ClauseNumberIterator { let inAnnex = false; let currentLevel = 0; let hasWarnedForExcessNesting = false; - const MAX_LEVELS = spec.opts.maxClauseDepth ?? Infinity; + // Ecma house style calls for a maximum of 5 clause levels + const MAX_LEVELS = spec.opts.maxClauseDepth ? spec.opts.maxClauseDepth || Infinity : 5; return { next(clauseStack: Clause[], node: HTMLElement) { @@ -32,12 +33,12 @@ export default function iterator(spec: Spec): ClauseNumberIterator { message: 'clause is being numbered without numbering its parent clause', }); } - if (!hasWarnedForExcessNesting && level + 1 > (spec.opts.maxClauseDepth ?? Infinity)) { + if (!hasWarnedForExcessNesting && level + 1 > MAX_LEVELS) { spec.warn({ type: 'node', node, ruleId: 'max-clause-depth', - message: `clause exceeds maximum nesting depth of ${spec.opts.maxClauseDepth}`, + message: `clause exceeds maximum nesting depth of ${MAX_LEVELS}`, }); hasWarnedForExcessNesting = true; } diff --git a/src/cli.ts b/src/cli.ts index fd038dbc..ae0745a6 100644 --- a/src/cli.ts +++ b/src/cli.ts @@ -116,6 +116,9 @@ const build = debounce(async function build() { if (args['max-clause-depth']) { opts.maxClauseDepth = args['max-clause-depth']; } + if (args['printed-toc-depth']) { + opts.tocDepth = args['printed-toc-depth']; + } if (args['no-toc'] != null) { opts.toc = !args['no-toc']; } diff --git a/src/ecmarkup.ts b/src/ecmarkup.ts index d642a6fe..a3a33dbb 100644 --- a/src/ecmarkup.ts +++ b/src/ecmarkup.ts @@ -33,6 +33,7 @@ export interface Options { date?: Date; location?: string; maxClauseDepth?: number; + tocDepth?: number; multipage?: boolean; extraBiblios?: ExportedBiblio[]; contributors?: string;