Skip to content

Commit 2c7b8c4

Browse files
committed
Auto number appendices and other cleanup
1 parent 10b7406 commit 2c7b8c4

6 files changed

+76
-74
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ features they make available to you.
3838

3939
- [remark-lint](https://github.com/remarkjs/remark-lint) -- Enforce markdown
4040
styles guide.
41+
- [remark-validate-links](https://github.com/remarkjs/remark-validate-links) --
42+
Check for broken links.
4143
- [remark-gfm](https://github.com/remarkjs/remark-gfm) -- Adds support for
4244
Github Flavored Markdown specific markdown features such as autolink literals,
4345
footnotes, strikethrough, tables, and tasklists.

build/build.js

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
1-
/* eslint-disable no-console */
21
import dotenv from "dotenv";
32
import { readFileSync, writeFileSync } from "node:fs";
43
import { reporter } from "vfile-reporter";
54
import { remark } from "remark";
6-
import remarkPresetLintMarkdownStyleGuide from "remark-preset-lint-markdown-style-guide";
7-
import remarkGfm from "remark-gfm";
8-
import remarkToc from "remark-toc";
9-
import torchLight from "remark-torchlight";
10-
import remarkRehype from "remark-rehype";
11-
import rehypeSlug from "rehype-slug";
125
import rehypeAutolinkHeadings from "rehype-autolink-headings";
6+
import rehypeSlug from "rehype-slug";
137
import rehypeStringify from "rehype-stringify";
14-
import remarkNumberHeadings from "./remark-number-headings.js";
158
import remarkFlexibleContainers from "remark-flexible-containers";
9+
import remarkGfm from "remark-gfm";
10+
import remarkNumberHeadings from "./remark-number-headings.js";
11+
import remarkPresetLintMarkdownStyleGuide from "remark-preset-lint-markdown-style-guide";
12+
import remarkRehype from "remark-rehype";
13+
import remarkToc from "remark-toc";
14+
import remarkValidateLinks from "remark-validate-links";
15+
import torchLight from "remark-torchlight";
1616

1717

1818
dotenv.config();
@@ -22,10 +22,20 @@ dotenv.config();
2222
const html = await remark()
2323
.use(remarkPresetLintMarkdownStyleGuide)
2424
.use(remarkGfm)
25-
.use(remarkNumberHeadings, { startDepth: 2, skip: ["Abstract", "Note to Readers", "Table of Contents"] })
26-
.use(remarkToc, { tight: true, heading: "Table of Contents" })
2725
.use(torchLight)
2826
.use(remarkFlexibleContainers)
27+
.use(remarkNumberHeadings, {
28+
startDepth: 2,
29+
skip: ["Abstract", "Note to Readers", "Table of Contents", "Authors' Addresses", "\\[.*\\]", "draft-.*"],
30+
appendixToken: "[Appendix]",
31+
appendixPrefix: "Appendix"
32+
})
33+
.use(remarkToc, {
34+
tight: true,
35+
heading: "Table of Contents",
36+
skip: "\\[.*\\]|draft-.*"
37+
})
38+
.use(remarkValidateLinks)
2939
.use(remarkRehype)
3040
.use(rehypeSlug)
3141
.use(rehypeAutolinkHeadings, { behavior: "wrap" })

build/remark-number-headings.js

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ const defaultOptions = {
88

99
const remarkNumberHeadings = (options) => (tree) => {
1010
options = { ...defaultOptions, ...options };
11+
options.skip = new RegExp(`^(${options.skip.join("|")})$`, "u");
1112

1213
let sectionNumbers = [];
1314

@@ -17,17 +18,28 @@ const remarkNumberHeadings = (options) => (tree) => {
1718
}
1819

1920
visit(node, "text", (textNode) => {
20-
const text = textNode.value ? textNode.value.trim() : "";
21+
let text = textNode.value ? textNode.value.trim() : "";
2122

22-
if (options.skip.includes(text)) {
23+
if (options.skip.test(text)) {
2324
return;
2425
}
2526

26-
sectionNumbers[node.depth] = (sectionNumbers[node.depth] ?? 0) + 1;
27-
sectionNumbers = sectionNumbers.slice(0, node.depth + 1);
28-
29-
const sectionNumber = sectionNumbers.slice(options.startDepth, node.depth + 1).join(".");
30-
textNode.value = `${sectionNumber}. ${text}`;
27+
if (text.startsWith(options.appendixToken)) {
28+
const currentIndex = typeof sectionNumbers[node.depth] === "string"
29+
? sectionNumbers[node.depth]
30+
: "@";
31+
sectionNumbers[node.depth] = String.fromCharCode(currentIndex.charCodeAt(0) + 1);
32+
sectionNumbers = sectionNumbers.slice(0, node.depth + 1);
33+
34+
const sectionNumber = sectionNumbers.slice(options.startDepth, node.depth + 1).join(".");
35+
textNode.value = `${options.appendixPrefix} ${sectionNumber}. ${text.slice(options.appendixToken.length + 1)}`;
36+
} else {
37+
sectionNumbers[node.depth] = (sectionNumbers[node.depth] ?? 0) + 1;
38+
sectionNumbers = sectionNumbers.slice(0, node.depth + 1);
39+
40+
const sectionNumber = sectionNumbers.slice(options.startDepth, node.depth + 1).join(".");
41+
textNode.value = `${sectionNumber}. ${text}`;
42+
}
3143
});
3244
});
3345
};

jsonschema-core.md

Lines changed: 26 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -2768,7 +2768,7 @@ Bray, T., Ed., Hollander, D., Ed., Layman, A., Ed., and R. Tobin, Ed.,
27682768
"Namespaces in XML 1.1 (Second Edition)", August 2006,
27692769
<<http://www.w3.org/TR/2006/REC-xml-names11-20060816>>.
27702770

2771-
## Appendix A. Schema identification examples
2771+
## [Appendix] Schema identification examples
27722772
Consider the following schema, which shows `$id` being used to identify both the
27732773
root schema and various subschemas, and `$anchor` being used to define plain
27742774
name fragment identifiers.
@@ -2841,12 +2841,12 @@ embedded schema
28412841
resources](#921-json-pointer-fragments-and-embedded-schema-resources) section
28422842
for futher comments.
28432843

2844-
## Appendix B. Manipulating schema documents and references
2844+
## [Appendix] Manipulating schema documents and references
28452845
Various tools have been created to rearrange schema documents based on how and
28462846
where references (`$ref`) appear. This appendix discusses which use cases and
28472847
actions are compliant with this specification.
28482848

2849-
### B.1. Bundling schema resources into a single document
2849+
### Bundling schema resources into a single document
28502850
A set of schema resources intended for use together can be organized with each
28512851
in its own schema document, all in the same schema document, or any granularity
28522852
of document grouping in between.
@@ -2868,7 +2868,7 @@ changing any aspect of validation or annotation results. The names of the
28682868
schemas under `$defs` do not affect behavior, assuming they are each unique, as
28692869
they do not appear in the canonical IRIs for the embedded resources.
28702870

2871-
### B.2. Reference removal is not always safe
2871+
### Reference removal is not always safe
28722872
Attempting to remove all references and produce a single schema document does
28732873
not, in all cases, produce a schema with identical behavior to the original
28742874
form.
@@ -2880,7 +2880,7 @@ scope of this specification to determine or provide a set of safe `$ref` removal
28802880
transformations, as they depend not only on the schema structure but also on the
28812881
intended usage.
28822882

2883-
## Appendix C. Example of recursive schema extension
2883+
## [Appendix] Example of recursive schema extension
28842884
Consider the following two schemas describing a simple recursive tree structure,
28852885
where each node in the tree can have a "data" field of any type. The first
28862886
schema allows and ignores other instance properties. The second is more strict
@@ -2976,9 +2976,9 @@ of the node schema objects were moved under `$defs`. It is the matching
29762976
`$dynamicAnchor` values which tell us how to resolve the dynamic reference, not
29772977
any sort of correlation in JSON structure.
29782978

2979-
## Appendix D. Working with vocabularies
2979+
## [Appendix] Working with vocabularies
29802980

2981-
### D.1. Best practices for vocabulary and meta-schema authors
2981+
### Best practices for vocabulary and meta-schema authors
29822982
Vocabulary authors should take care to avoid keyword name collisions if the
29832983
vocabulary is intended for broad use, and potentially combined with other
29842984
vocabularies. JSON Schema does not provide any formal namespacing system, but
@@ -3026,7 +3026,7 @@ resulting behavior is undefined.
30263026
Meta-schemas intended for local use, with no need to test for vocabulary support
30273027
in arbitrary implementations, can safely omit `$vocabulary` entirely.
30283028

3029-
### D.2. Example meta-schema with vocabulary declarations
3029+
### Example meta-schema with vocabulary declarations
30303030
This meta-schema explicitly declares both the Core and Applicator vocabularies,
30313031
together with an extension vocabulary, and combines their meta-schemas with an
30323032
`allOf`. The extension vocabulary's meta-schema, which describes only the
@@ -3118,7 +3118,7 @@ to ensure that it is validated even when `format` functions purely as an
31183118
annotation, as explained in the [Validation
31193119
specification](#json-schema-validation).
31203120

3121-
## Appendix E. References and generative use cases
3121+
## [Appendix] References and generative use cases
31223122
While the presence of references is expected to be transparent to validation
31233123
results, generative use cases such as code generators and UI renderers often
31243124
consider references to be semantically significant.
@@ -3167,7 +3167,7 @@ instance of a distinct class.
31673167
This style of usage requires the annotation to be in the same object as the
31683168
reference, which must be recognizable as a reference.
31693169

3170-
## Appendix F. Acknowledgments
3170+
## [Appendix] Acknowledgments
31713171
Thanks to Gary Court, Francis Galiegue, Kris Zyp, Geraint Luff, and Henry
31723172
Andrews for their work on the initial drafts of JSON Schema.
31733173

@@ -3176,16 +3176,16 @@ Bowman, Gowry Sankar, Donald Pipowitch, Dave Finlay, Denis Laxalde, Phil
31763176
Sturgeon, Shawn Silverman, and Karen Etheridge for their submissions and patches
31773177
to the document.
31783178

3179-
## Appendix G. Change Log[^19]
3179+
## [Appendix] Change Log[^19]
31803180
[^19]: This section to be removed before leaving Internet-Draft status.
31813181

3182-
### G.1. draft-bhutton-json-schema-next
3182+
### draft-bhutton-json-schema-next
31833183
- `contains` now applies to objects as well as arrays
31843184
- Use IRIs instead of URIs
31853185
- Remove bookending requirement for `$dynamicRef`
31863186
- Add `propertyDependencies` keyword
31873187

3188-
### G.2. draft-bhutton-json-schema-01
3188+
### draft-bhutton-json-schema-01
31893189
- Improve and clarify the `type`, `contains`, `unevaluatedProperties`, and
31903190
`unevaluatedItems` keyword explanations
31913191
- Clarify various aspects of "canonical URIs"
@@ -3194,7 +3194,7 @@ to the document.
31943194
- Remove references to remaining media-type parameters
31953195
- Fix multiple examples
31963196

3197-
### G.3. draft-bhutton-json-schema-00
3197+
### draft-bhutton-json-schema-00
31983198
- `$schema` MAY change for embedded resources
31993199
- Array-value `items` functionality is now `prefixItems`
32003200
- `items` subsumes the old function of `additionalItems`
@@ -3211,7 +3211,7 @@ interactions now specified
32113211
- Moved `unevaluatedItems` and `unevaluatedProperties` from core into their own
32123212
vocabulary
32133213

3214-
### G.4. draft-handrews-json-schema-02
3214+
### draft-handrews-json-schema-02
32153215
- Update to RFC 8259 for JSON specification
32163216
- Moved `definitions` from the Validation specification here as `$defs`
32173217
- Moved applicator keywords from the Validation specification as their own
@@ -3237,7 +3237,7 @@ meta-schemas
32373237
- Clarified that the behavior of JSON Pointers across `$id` boundary is
32383238
unreliable
32393239

3240-
### G.5. draft-handrews-json-schema-01
3240+
### draft-handrews-json-schema-01
32413241
- This draft is purely a clarification with no functional changes
32423242
- Emphasized annotations as a primary usage of JSON Schema
32433243
- Clarified $id by use cases
@@ -3250,7 +3250,7 @@ schema identifiers during parsing
32503250
same process
32513251
- Minor formatting improvements
32523252

3253-
### G.6. draft-handrews-json-schema-00
3253+
### draft-handrews-json-schema-00
32543254
- Make the concept of a schema keyword vocabulary more clear
32553255
- Note that the concept of "integer" is from a vocabulary, not the data model
32563256
- Classify keywords as assertions or annotations and describe their general
@@ -3262,7 +3262,7 @@ behavior
32623262
- Add `application/schema-instance+json` media type
32633263
- Recommend a "schema" link relation / parameter instead of "profile"
32643264

3265-
### G.7. draft-wright-json-schema-01
3265+
### draft-wright-json-schema-01
32663266
- Updated intro
32673267
- Allowed for any schema to be a boolean
32683268
- `$schema` SHOULD NOT appear in subschemas, although that may change
@@ -3271,7 +3271,7 @@ behavior
32713271
- Note applicability to formats such as CBOR that can be represented in the JSON
32723272
data model
32733273

3274-
### G.8. draft-wright-json-schema-00
3274+
### draft-wright-json-schema-00
32753275
- Updated references to JSON
32763276
- Updated references to HTTP
32773277
- Updated references to JSON Pointer
@@ -3286,7 +3286,7 @@ data model
32863286
- Rewrote section on usage with rel="describedBy" and rel="profile"
32873287
- Fixed numerous invalid examples
32883288

3289-
### G.9. draft-zyp-json-schema-04
3289+
### draft-zyp-json-schema-04
32903290
- Salvaged from draft v3.
32913291
- Split validation keywords into separate document.
32923292
- Split hypermedia keywords into separate document.
@@ -3295,23 +3295,12 @@ data model
32953295
- Define the role of `id`. Define URI resolution scope.
32963296
- Add interoperability considerations.
32973297

3298-
### G.10. draft-zyp-json-schema-00
3298+
### draft-zyp-json-schema-00
32993299
- Initial draft.
33003300

33013301
## Authors' Addresses
3302-
3303-
### Austin Wright (*editor*)
3304-
3305-
3306-
### Ben Hutton (*editor*)
3307-
Postman
3308-
3309-
3310-
3311-
URI: <https://jsonschema.dev>
3312-
3313-
### Greg Dennis
3314-
3315-
3316-
3317-
URI: <https://github.com/gregsdennis>
3302+
| Author | Company | Email | URI |
3303+
|--------------------------|---------|-------------------------|----------------------------------|
3304+
| Austin Wright (*editor*) | | <[email protected]> | |
3305+
| Ben Hutton (*editor*) | Postman | <[email protected]> | <https://jsonschema.dev> |
3306+
| Greg Dennis | | <[email protected]> | <https://github.com/gregsdennis> |

jsonschema-validation.md

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -895,7 +895,7 @@ draft-bhutton-json-schema-01, June 2022,
895895
Hoehrmann, B., "Scripting Media Types", RFC 4329, DOI 10.17487/RFC4329, April
896896
2006, <<https://www.rfc-editor.org/info/rfc4329>>.
897897

898-
## Appendix A. Keywords Moved from Validation to Core
898+
## [Appendix] Keywords Moved from Validation to Core
899899
Several keywords have been moved from this document into the [Core
900900
Specification](#json-schema) starting with draft 2019-09, in some cases with
901901
re-naming or other changes. This affects the following former validation
@@ -928,7 +928,7 @@ property. The property name array form is retained here and renamed to
928928
`dependentRequired`, as it is an assertion which is a shortcut for the
929929
conditional use of the `required` assertion keyword.
930930

931-
## Appendix B. Acknowledgments
931+
## [Appendix] Acknowledgments
932932
Thanks to Gary Court, Francis Galiegue, Kris Zyp, Geraint Luff, and Henry
933933
Andrews for their work on the initial drafts of JSON Schema.
934934

@@ -937,7 +937,7 @@ Bowman, Gowry Sankar, Donald Pipowitch, Dave Finlay, Denis Laxalde, Phil
937937
Sturgeon, Shawn Silverman, and Karen Etheridge for their submissions and patches
938938
to the document.
939939

940-
## Appendix C. ChangeLog[^6]
940+
## [Appendix] ChangeLog[^6]
941941
[^6]: This section to be removed before leaving Internet-Draft status.
942942

943943
- *draft-next*
@@ -1032,15 +1032,7 @@ schema form to the core spec
10321032
- Add interoperability considerations.
10331033

10341034
## Authors' Addresses
1035-
1036-
### Austin Wright (*editor*)
1037-
1038-
1039-
1040-
### Ben Hutton (*editor*)
1041-
1042-
Postman
1043-
1044-
1045-
1046-
URI: <https://jsonschema.dev>
1035+
| Author | Company | Email | URI |
1036+
|--------------------------|---------|----------------------|--------------------------|
1037+
| Austin Wright (*editor*) | | <[email protected]> | |
1038+
| Ben Hutton (*editor*) | Postman | <[email protected]> | <https://jsonschema.dev> |

package.json

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
"type": "module",
66
"main": "index.js",
77
"scripts": {
8-
"lint": "eslint *.js",
98
"build": "npm run build-core && npm run build-validation",
109
"build-core": "node build/build.js < jsonschema-core.md > jsonschema-core.html",
1110
"build-validation": "node build/build.js < jsonschema-validation.md > jsonschema-validation.html"
@@ -22,12 +21,10 @@
2221
"remark-rehype": "^10.1.0",
2322
"remark-toc": "^8.0.1",
2423
"remark-torchlight": "^0.0.5",
24+
"remark-validate-links": "^12.1.1",
2525
"vfile-reporter": "^8.0.0"
2626
},
2727
"devDependencies": {
28-
"dotenv": "^16.3.1",
29-
"eslint": "*",
30-
"eslint-import-resolver-node": "*",
31-
"eslint-plugin-import": "*"
28+
"dotenv": "^16.3.1"
3229
}
3330
}

0 commit comments

Comments
 (0)