Skip to content

feat(core/grammar-boxes): add styled ABNF, EBNF, and BNF pre blocks#5294

Draft
marcoscaceres wants to merge 4 commits into
mainfrom
feat/3523-grammar-boxes
Draft

feat(core/grammar-boxes): add styled ABNF, EBNF, and BNF pre blocks#5294
marcoscaceres wants to merge 4 commits into
mainfrom
feat/3523-grammar-boxes

Conversation

@marcoscaceres
Copy link
Copy Markdown
Contributor

Closes #3523

Adds header badges, copy buttons, and syntax highlighting for grammar blocks. Authors add class="abnf", class="ebnf", or class="bnf" to a <pre> element. The module wraps content in <code>, adds an ID-linked header badge, and registers the languages with highlight.js for syntax coloring.

Adds `src/core/grammar-boxes.js` which processes `<pre class="abnf">`,
`<pre class="ebnf">`, and `<pre class="bnf">` blocks, giving each a
header badge (matching the WebIDL/CDDL pattern) with a self-link and
copy button. Content is wrapped in a `<code>` element so that the
existing `core/highlight` module can apply syntax highlighting via
highlight.js. Registers `ebnf` and `bnf` languages in the highlight
worker (ABNF was already registered).

Use `data-no-grammar` to opt out of processing for a specific block.

Closes #3523
Closes #3525
- Add .highlight class to processed pre elements (prevents double-highlighting)
- Fix light mode contrast: use #005a9c (dark blue) text on light blue badge
- Remove duplicate --grammar-focus in dark mode block
- Collapse CSS selectors with :is(.abnf, .ebnf, .bnf)
- Scope focus-visible to .grammarHeader anchors only
- Remove stale module comment about auto-detection
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a new core module to render “grammar boxes” for <pre class="abnf|ebnf|bnf">, aligning them with existing WebIDL/CDDL UX (header badge, copy button, and highlight.js-based syntax highlighting).

Changes:

  • Register bnf and ebnf languages in the highlight.js worker allowlist/registry.
  • Introduce core/grammar-boxes to wrap grammar <pre> content in <code>, add a self-link header badge, and attach a copy button + injected CSS.
  • Add a dedicated spec test suite covering wrapping, header/self-linking, copy button presence, opt-out via data-no-grammar, and CSS injection.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
worker/respec-highlight.js Registers BNF/EBNF with highlight.js and adds them to the configured language set.
tests/spec/core/grammar-boxes-spec.js New spec tests validating grammar box DOM structure and CSS injection behavior.
src/styles/grammar.css.js New CSS for ABNF/EBNF/BNF pre blocks and the shared grammar header badge styling.
src/core/grammar-boxes.js New core plugin that transforms grammar <pre> blocks (wraps in <code>, adds header badge + copy button, injects CSS).
profiles/w3c.js Wires the new module into the W3C profile plugin pipeline.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread profiles/w3c.js
Comment thread src/core/grammar-boxes.js
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ABNF boxes

2 participants