-
-
Notifications
You must be signed in to change notification settings - Fork 427
feat(core/cddl): add CDDL support #5201
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
Merged
Merged
Changes from all commits
Commits
Show all changes
25 commits
Select commit
Hold shift + click to select a range
27b936b
feat(core/cddl): add CDDL support with parsing, highlighting, and cro…
marcoscaceres 6b302a5
fix(core/cddl): address review feedback for index and clipboard handling
Copilot d5ea37a
docs(core/cddl-index): clarify optional consolidated index id param
Copilot 9a94e1e
fix(tests): fix Copilot's heading test to account for header-wrapper
marcoscaceres b0b5214
fix: address Sid review findings
marcoscaceres f7e97d4
fix: address accessibility, security, and export review findings
marcoscaceres 6bb1613
fix: modernize CSS units, add lang attr, update basic.built.html
marcoscaceres d831ea1
fix(core/cddl): avoid duplicate unresolved inline-ref warnings
Copilot 54ccdf9
fix(cddl): address review blockers
marcoscaceres 43314df
fix(core/cddl): register prose-defined value defs for inline refs
Copilot 678a933
chore(core/cddl): fix TS6 lint issues after rebase
Copilot 85a03e0
fix(core/cddl): tighten definition link resolution after TS6 lint pass
Copilot 947c2b2
fix(cddl): address Sid's review feedback
marcoscaceres 7b87940
Merge branch 'main' into feat/cddl-support
marcoscaceres 2d8533f
fix(core/cddl): resolve TS6 CI lint errors in cddl and cddl-index
Copilot ebaeeea
refactor(core/cddl-index): initialize module bucket before push
Copilot e787cac
test(core/cddl): align invalid syntax expectation with processing err…
Copilot ed8ff9d
chore: revert unintended builds artifact updates
Copilot a2d9832
chore(ci): align builds outputs with main
Copilot 865817c
Merge branch 'main' into feat/cddl-support
marcoscaceres 523ec6a
fix(core/cddl): address Sid's review feedback
marcoscaceres d146fd1
fix(core/cddl): apply html tag to template strings, use renameElement
marcoscaceres be2e591
fix(core/cddl): add type assertion for attr in normalizeProseDfns
marcoscaceres e191ab9
Merge branch 'main' into feat/cddl-support
marcoscaceres 42558ab
Merge branch 'main' into feat/cddl-support
sidvishnoi 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 hidden or 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
This file contains hidden or 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
This file contains hidden or 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or 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
This file contains hidden or 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,131 @@ | ||
| // @ts-check | ||
| /** | ||
| * Module: core/cddl-index | ||
| * Constructs a summary of CDDL in the document by | ||
| * cloning all the generated CDDL nodes and | ||
| * appending them to a pre element. | ||
| * | ||
| * Usage: | ||
| * Add a <section id="cddl-index"> to the document. | ||
| * It also supports title elements to generate a header. | ||
| * Or if a header element is an immediate child, then | ||
| * that is preferred. | ||
| */ | ||
| export const name = "core/cddl-index"; | ||
| import { nonNormativeSelector, renameElement } from "./utils.js"; | ||
|
|
||
| export function run() { | ||
| /** @type {HTMLElement | null} */ | ||
| const cddlIndexSec = document.querySelector("section#cddl-index"); | ||
| if (!cddlIndexSec) { | ||
| return; | ||
| } | ||
|
|
||
| if ( | ||
| !cddlIndexSec.querySelector(":scope > :is(h2, h3, h4, h5, h6):first-child") | ||
| ) { | ||
| const heading = document.createElement("h2"); | ||
| if (cddlIndexSec.title) { | ||
| heading.textContent = cddlIndexSec.title; | ||
| cddlIndexSec.removeAttribute("title"); | ||
| } else { | ||
| heading.textContent = "CDDL Index"; | ||
| } | ||
| cddlIndexSec.prepend(heading); | ||
| } | ||
|
|
||
| // Filter out CDDL marked with class="exclude" and in non-normative sections | ||
| const cddlBlocks = /** @type {HTMLElement[]} */ ( | ||
| Array.from( | ||
| document.querySelectorAll("pre.cddl:not(.exclude) > code") | ||
| ).filter(cddl => !cddl.closest(nonNormativeSelector)) | ||
| ); | ||
|
|
||
| if (cddlBlocks.length === 0) { | ||
| const text = "This specification doesn't normatively declare any CDDL."; | ||
| cddlIndexSec.append(text); | ||
| return; | ||
| } | ||
|
|
||
| // Group by module if data-cddl-module is used | ||
| /** @type {Map<string, HTMLElement[]>} */ | ||
| const modules = new Map(); | ||
| for (const cddlCode of cddlBlocks) { | ||
| const pre = cddlCode.closest("pre"); | ||
| const moduleName = | ||
| /** @type {HTMLElement} */ (pre)?.dataset.cddlModule || ""; | ||
| let moduleBlocks = modules.get(moduleName); | ||
| if (!moduleBlocks) { | ||
| moduleBlocks = []; | ||
| modules.set(moduleName, moduleBlocks); | ||
| } | ||
| moduleBlocks.push(/** @type {HTMLElement} */ (cddlCode)); | ||
| } | ||
|
|
||
| // Check if we have multiple modules | ||
| const hasModules = | ||
| modules.size > 1 || (modules.size === 1 && !modules.has("")); | ||
|
|
||
| if (hasModules) { | ||
| modules.forEach((blocks, moduleName) => { | ||
| const section = document.createElement("section"); | ||
| const heading = document.createElement("h3"); | ||
| const displayName = moduleName || "Default"; | ||
| heading.textContent = `Module: ${displayName}`; | ||
| if (moduleName) { | ||
| heading.id = `cddl-index-module-${moduleName.toLowerCase().replace(/[^a-z0-9]+/g, "-")}`; | ||
| } | ||
| section.append(heading); | ||
| section.append(createConsolidatedPre(blocks)); | ||
| cddlIndexSec.append(section); | ||
| }); | ||
| } else { | ||
| // Single consolidated pre | ||
| cddlIndexSec.append(createConsolidatedPre(cddlBlocks, "actual-cddl-index")); | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Create a consolidated <pre class="cddl"> from multiple code blocks. | ||
| * @param {HTMLElement[]} cddlCodes - array of <code> elements inside <pre class="cddl"> | ||
| * @param {string} [id] - optional id (used for the single consolidated index pre) | ||
| * @returns {HTMLPreElement} | ||
| */ | ||
| function createConsolidatedPre(cddlCodes, id) { | ||
| const pre = document.createElement("pre"); | ||
| pre.classList.add("cddl", "def", "highlight"); | ||
| if (id) { | ||
| pre.id = id; | ||
| } | ||
|
|
||
| const code = document.createElement("code"); | ||
| cddlCodes | ||
| .map(elem => { | ||
| const fragment = document.createDocumentFragment(); | ||
| elem.childNodes.forEach(child => | ||
| fragment.appendChild(child.cloneNode(true)) | ||
| ); | ||
| return fragment; | ||
| }) | ||
| .forEach(fragment => { | ||
| if (code.lastChild) { | ||
| code.append("\n\n"); | ||
| } | ||
| code.appendChild(fragment); | ||
| }); | ||
|
|
||
| // Remove duplicate IDs | ||
| code.querySelectorAll("*[id]").forEach(elem => elem.removeAttribute("id")); | ||
|
|
||
| // Replace dfns with spans so the index doesn't create duplicate definitions | ||
| code.querySelectorAll("dfn").forEach(dfn => { | ||
| const span = renameElement(dfn, "span"); | ||
| span.removeAttribute("data-export"); | ||
| for (const attr of [...span.attributes]) { | ||
| if (attr.name.startsWith("data-dfn")) span.removeAttribute(attr.name); | ||
| } | ||
| }); | ||
|
|
||
| pre.append(code); | ||
| return pre; | ||
| } | ||
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.
Uh oh!
There was an error while loading. Please reload this page.