-
Notifications
You must be signed in to change notification settings - Fork 1
Updated block validation integration #68
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
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
Some comments aren't visible on the classic Files Changed page.
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
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 |
|---|---|---|
| @@ -1,83 +1,3 @@ | ||
| const BLOCK_NAME = 'bibliography-builder/bibliography'; | ||
|
|
||
| const RAW_URL_RE = /^https?:\/\/\S+$|^10\.\d{4,}\/\S+$/i; | ||
|
|
||
| function isRawUrlText(text) { | ||
| return typeof text === 'string' && RAW_URL_RE.test(text.trim()); | ||
| } | ||
|
|
||
| function hasRawUrlLinks(citations) { | ||
| if (!Array.isArray(citations)) { | ||
| return false; | ||
| } | ||
| return citations.some((csl) => { | ||
| const url = csl?.URL || csl?.DOI; | ||
| const title = csl?.title; | ||
| if (!url) { | ||
| return false; | ||
| } | ||
| return !title || isRawUrlText(title); | ||
| }); | ||
| } | ||
|
|
||
| const checks = [ | ||
| { | ||
| id: 'empty_bibliography', | ||
| message: | ||
| 'This bibliography block has no citations. Empty blocks are omitted from the published page.', | ||
| severity: 'error', | ||
| test(attributes) { | ||
| const { citations } = attributes; | ||
| return !Array.isArray(citations) || citations.length === 0; | ||
| }, | ||
| }, | ||
| { | ||
| id: 'heading_missing', | ||
| message: | ||
| 'This bibliography block has citations but no visible heading or accessible label. Add a heading so readers can identify the reference list.', | ||
| severity: 'warning', | ||
| test(attributes) { | ||
| const { citations, headingText } = attributes; | ||
| const hasCitations = | ||
| Array.isArray(citations) && citations.length > 0; | ||
| const hasHeading = | ||
| typeof headingText === 'string' && headingText.trim() !== ''; | ||
| return hasCitations && !hasHeading; | ||
| }, | ||
| }, | ||
| { | ||
| id: 'raw_url_link_text', | ||
| message: | ||
| 'One or more citations have a URL or DOI as the only identifier. A descriptive title helps screen reader users understand the link destination.', | ||
| severity: 'warning', | ||
| test(attributes) { | ||
| return hasRawUrlLinks(attributes.citations); | ||
| }, | ||
| }, | ||
| { | ||
| id: 'all_metadata_disabled', | ||
| message: | ||
| 'All machine-readable metadata outputs (JSON-LD, COinS, CSL-JSON) are disabled. Enabling at least one improves citation-manager interoperability.', | ||
| severity: 'warning', | ||
| test(attributes) { | ||
| const { outputJsonLd, outputCoins, outputCslJson } = attributes; | ||
| return !outputJsonLd && !outputCoins && !outputCslJson; | ||
| }, | ||
| }, | ||
| ]; | ||
|
|
||
| export function registerBACChecks() { | ||
| if ( | ||
| typeof window === 'undefined' || | ||
| typeof window.BlockAccessibilityChecks === 'undefined' | ||
| ) { | ||
| return; | ||
| } | ||
|
|
||
| const { registerBlockChecks } = window.BlockAccessibilityChecks; | ||
| if (typeof registerBlockChecks !== 'function') { | ||
| return; | ||
| } | ||
|
|
||
| registerBlockChecks(BLOCK_NAME, checks); | ||
| } | ||
| // BAC v3 window-global integration path removed in v4. | ||
| // All checks are now registered via ba11yc_register_block_check() in PHP | ||
| // and validated via the ba11yc.validateBlock filter in src/validation.js. |
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.