-
-
Notifications
You must be signed in to change notification settings - Fork 263
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Convert core/validation specs to non-IETF markdown #1425
Merged
Merged
Changes from 8 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
10b7406
Convert core/validation specs to non-IETF markdown
jdesrosiers 2c7b8c4
Auto number appendices and other cleanup
jdesrosiers b03c4b2
Add markdown syntax for section links
jdesrosiers 563526d
Add eslint
jdesrosiers c59dd4a
Use custom toc and heading-links remark plugins
jdesrosiers d16b300
Fix some markdown bugs and style issues
jdesrosiers a5e139a
Fix bugs
jdesrosiers 3f815ab
Add code-titles plugin
jdesrosiers 665c71a
Fix node build config details
jdesrosiers 678d100
Remove core and validation from Makefile
jdesrosiers 24c90ec
Add major pinning version for dev dependencies
jdesrosiers File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
{ | ||
"root": true, | ||
"env": { | ||
"es6": true, | ||
"node": true | ||
}, | ||
"parserOptions": { | ||
"ecmaVersion": 2020, | ||
"sourceType": "module" | ||
}, | ||
"extends": [ | ||
"eslint:recommended", | ||
"plugin:import/recommended" | ||
], | ||
"plugins": ["import"], | ||
"rules": { | ||
"array-bracket-spacing": "error", | ||
"arrow-parens": "error", | ||
"comma-dangle": "error", | ||
"dot-location": ["error", "property"], | ||
"eol-last": "error", | ||
"generator-star-spacing": ["error", { "before": false, "after": true }], | ||
"indent": ["error", 2, { "ignoreComments": true, "SwitchCase": 1 }], | ||
"linebreak-style": "error", | ||
"no-console": ["error", { "allow": ["error"] }], | ||
"no-trailing-spaces": "error", | ||
"no-unused-vars": ["error", { "argsIgnorePattern": "_.*" }], | ||
"prefer-const": ["error", { "destructuring": "all" }], | ||
"semi": "error", | ||
"quotes": ["error", "double", { "allowTemplateLiterals": true }] | ||
}, | ||
"settings": { | ||
"import/resolver": "node" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,3 +7,8 @@ relative-json-pointer.txt | |
|
||
# For the Python enviornment | ||
.venv | ||
|
||
package-lock.json | ||
node_modules/ | ||
|
||
.env |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import { visit } from "unist-util-visit"; | ||
import { text } from "mdast-builder"; | ||
|
||
|
||
const hexdig = `[0-9a-fA-F]`; | ||
const char = `(?:\\\\["\\/\\\\brfnt]|\\\\u${hexdig}{4}|[^"\\\\])`; | ||
const jsonStringPattern = new RegExp(`^"${char}*"`); | ||
|
||
const remarkNumberHeadings = () => (tree) => { | ||
visit(tree, "code", (codeNode, index, parent) => { | ||
// Support title without a language | ||
if (codeNode.lang && codeNode.lang[0] === "\"") { | ||
codeNode.meta = `${codeNode.lang} ${codeNode.meta}`; | ||
codeNode.lang = null; | ||
} | ||
|
||
let title = ""; | ||
const titleClasses = ["remark-code-title"]; | ||
|
||
const language = codeNode.lang ?? ""; | ||
if (language.toLowerCase() === "jsonschema") { | ||
codeNode.lang = "json"; | ||
title = "JSON Schema"; | ||
titleClasses.push("code-title-jsonschema"); | ||
} else if (language.toLowerCase() === "json") { | ||
title = "JSON"; | ||
titleClasses.push("code-title-json"); | ||
} else { | ||
titleClasses.push("code-title-unknown"); | ||
} | ||
|
||
if ("meta" in codeNode) { | ||
const match = jsonStringPattern.exec(codeNode.meta); | ||
if (match) { | ||
const customTitle = JSON.parse(match[0]); | ||
title = title ? `${title} - ${customTitle}` : customTitle; | ||
codeNode.meta = codeNode.meta.slice(match[0].length).trim(); | ||
} | ||
} | ||
|
||
const containerChildren = []; | ||
if (title) { | ||
const titleNode = div([text(title)], { className: titleClasses }); | ||
containerChildren.push(titleNode); | ||
} | ||
containerChildren.push(codeNode); | ||
|
||
const wrappedCodeNode = div(containerChildren, { className: ["remark-code-container"] }); | ||
|
||
parent.children.splice(index, 1, wrappedCodeNode); | ||
}); | ||
}; | ||
|
||
const div = (children, properties) => { | ||
return { | ||
type: "container", | ||
children, | ||
data: { | ||
hName: "div", | ||
hProperties: properties | ||
} | ||
}; | ||
}; | ||
|
||
export default remarkNumberHeadings; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
import { visit } from "unist-util-visit"; | ||
import { link, text } from "mdast-builder"; | ||
import { findAndReplace } from "mdast-util-find-and-replace"; | ||
import { toString as nodeToString } from "mdast-util-to-string"; | ||
|
||
|
||
const defaultOptions = { | ||
startDepth: 1, | ||
skip: [], | ||
appendixToken: "[Appendix]", | ||
appendixPrefix: "Appendix" | ||
}; | ||
|
||
const remarkNumberHeadings = (options) => (tree, file) => { | ||
options = { ...defaultOptions, ...options }; | ||
options.skip = new RegExp(`^(${options.skip.join("|")})$`, "u"); | ||
|
||
// Auto-number headings | ||
let sectionNumbers = []; | ||
|
||
visit(tree, "heading", (headingNode) => { | ||
if (headingNode.depth < options.startDepth) { | ||
return; | ||
} | ||
|
||
const headingText = nodeToString(headingNode); | ||
if (options.skip.test(headingText)) { | ||
return; | ||
} | ||
|
||
if (!("data" in headingNode)) { | ||
headingNode.data = {}; | ||
} | ||
|
||
if (!("hProperties" in headingNode.data)) { | ||
headingNode.data.hProperties = {}; | ||
} | ||
|
||
if (headingText.startsWith(options.appendixToken)) { | ||
findAndReplace(headingNode, [options.appendixToken]); | ||
|
||
const currentIndex = typeof sectionNumbers[headingNode.depth] === "string" | ||
? sectionNumbers[headingNode.depth] | ||
: "@"; | ||
sectionNumbers[headingNode.depth] = String.fromCharCode(currentIndex.charCodeAt(0) + 1); | ||
sectionNumbers = sectionNumbers.slice(0, headingNode.depth + 1); | ||
|
||
const sectionNumber = sectionNumbers.slice(options.startDepth, headingNode.depth + 1).join("."); | ||
headingNode.data.section = `${options.appendixPrefix} ${sectionNumber}`; | ||
|
||
headingNode.children.splice(0, 0, text(`${headingNode.data.section}. `)); | ||
} else { | ||
sectionNumbers[headingNode.depth] = (sectionNumbers[headingNode.depth] ?? 0) + 1; | ||
sectionNumbers = sectionNumbers.slice(0, headingNode.depth + 1); | ||
|
||
const sectionNumber = sectionNumbers.slice(options.startDepth, headingNode.depth + 1).join("."); | ||
const prefix = typeof sectionNumbers[options.startDepth] === "string" | ||
? options.appendixPrefix | ||
: "Section"; | ||
headingNode.data.section = `${prefix} ${sectionNumber}`; | ||
|
||
headingNode.children.splice(0, 0, text(`${sectionNumber}. `)); | ||
} | ||
|
||
if (!("id" in headingNode.data)) { | ||
const sectionSlug = headingNode.data?.id | ||
?? headingNode.data.section.replaceAll(/[ .]/g, "-").toLowerCase(); | ||
headingNode.data.hProperties.id = sectionSlug; | ||
headingNode.data.id = sectionSlug; | ||
} | ||
}); | ||
|
||
// Build headings data used by ./remark-reference-links.js | ||
if (!("data" in file)) { | ||
file.data = {}; | ||
} | ||
|
||
file.data.headings = {}; | ||
|
||
visit(tree, "heading", (headingNode) => { | ||
if (headingNode.data?.id) { | ||
if (headingNode.data.id in file.data.headings) { | ||
file.message(`Found duplicate heading id "${headingNode.data.id}"`); | ||
} | ||
file.data.headings[headingNode.data.id] = headingNode; | ||
} | ||
}); | ||
|
||
// Make heading a link | ||
visit(tree, "heading", (headingNode) => { | ||
if (headingNode.data?.id) { | ||
headingNode.children = [link(`#${headingNode.data.id}`, "", headingNode.children)]; | ||
} | ||
}); | ||
}; | ||
|
||
export default remarkNumberHeadings; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { text, link } from "mdast-builder"; | ||
import { toString as nodeToString } from "mdast-util-to-string"; | ||
import { findAndReplace } from "mdast-util-find-and-replace"; | ||
|
||
|
||
const referenceLink = /\{\{(?<id>.*?)\}\}/ug; | ||
|
||
const remarkReferenceLinks = () => (tree, file) => { | ||
findAndReplace(tree, [referenceLink, (value, id) => { | ||
// file.data.headings comes from ./remark-headings.js | ||
if (!(id in file.data.headings)) { | ||
throw Error(`ReferenceLinkError: No header found with id "${id}"`); | ||
} | ||
|
||
const headerText = nodeToString(file.data.headings[id]); | ||
const linkText = text(file.data.headings[id].data.section); | ||
return link(`#${id}`, headerText, [linkText]); | ||
}]); | ||
}; | ||
|
||
export default remarkReferenceLinks; |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd have thought we very much wanted to include the package-lock.json file.
What's the reason for git ignoring it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That shouldn't be there. I'll remove it. My philosophy is that package-lock should be checked-in for applications, but not for libraries. Most of the code I work on is for libraries, so that got added by mistake due to force of habit.