forked from bpampuch/pdfmake
-
Notifications
You must be signed in to change notification settings - Fork 0
Add accessibilty tagging #2
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
Open
stuartwilkes
wants to merge
3
commits into
wellcome-main
Choose a base branch
from
task/accessibilty-v2
base: wellcome-main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
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
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
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
Large diffs are not rendered by default.
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,96 @@ | ||
| 'use strict'; | ||
|
|
||
| /** | ||
| * Utility module to extract accessibility-relevant properties from document nodes | ||
| * and determine their PDF structure type. | ||
| */ | ||
|
|
||
| /** | ||
| * Returns the PDF structure tag for a node based on its properties. | ||
| * | ||
| * @param {Object} node - A pdfmake document node | ||
| * @param {Object} [context] - Optional context about the node's position in the document tree | ||
| * @param {boolean} [context.inList] - Whether the node is inside a list | ||
| * @param {boolean} [context.inTable] - Whether the node is inside a table | ||
| * @returns {string} The PDF structure type (e.g. 'P', 'H1', 'Figure', 'Artifact') | ||
| */ | ||
| function getAccessibilityRole(node, context) { | ||
| if (!node) { | ||
| return 'Artifact'; | ||
| } | ||
|
|
||
| // Explicit accessibilityTag takes precedence | ||
| if (node.accessibilityTag) { | ||
| return node.accessibilityTag; | ||
| } | ||
|
|
||
| // Headings via headlineLevel | ||
| if (node.headlineLevel && node.headlineLevel >= 1 && node.headlineLevel <= 6) { | ||
| return 'H' + node.headlineLevel; | ||
| } | ||
|
|
||
| // Images and SVGs - Figure if alt/actualText present, otherwise Artifact | ||
| if (node.image || node.svg) { | ||
| if (node.alt || node.actualText) { | ||
| return 'Figure'; | ||
| } | ||
| return 'Artifact'; | ||
| } | ||
|
|
||
| // Canvas / vectors are always artifacts | ||
| if (node.canvas) { | ||
| return 'Artifact'; | ||
| } | ||
|
|
||
| // Tables - only tagged if explicitly marked | ||
| if (node.table) { | ||
| if (node.accessibilityTag === 'Table' || node.accessibilityTag === 'TOC') { | ||
| return node.accessibilityTag; | ||
| } | ||
| return null; // no structural tagging for unmarked tables | ||
| } | ||
|
|
||
| // Text nodes default to P (paragraph) | ||
| if (node.text !== undefined) { | ||
| return 'P'; | ||
| } | ||
|
|
||
| return null; | ||
| } | ||
|
|
||
| /** | ||
| * Returns options for pdfKitDoc.struct() based on node properties. | ||
| */ | ||
| function getStructureOptions(node) { | ||
| var options = {}; | ||
|
|
||
| if (node.alt) { | ||
| options.alt = node.alt; | ||
| } | ||
| if (node.actualText) { | ||
| options.actual = node.actualText; | ||
| } | ||
|
|
||
| return options; | ||
| } | ||
|
|
||
| /** | ||
| * Checks if a table node should be structurally tagged. | ||
| */ | ||
| function shouldTagTable(node) { | ||
| return node && (node.accessibilityTag === 'Table' || node.accessibilityTag === 'TOC'); | ||
| } | ||
|
|
||
| /** | ||
| * Checks if a table node is a Table of Contents. | ||
| */ | ||
| function isTOC(node) { | ||
| return node && node.accessibilityTag === 'TOC'; | ||
| } | ||
|
|
||
| module.exports = { | ||
| getAccessibilityRole: getAccessibilityRole, | ||
| getStructureOptions: getStructureOptions, | ||
| shouldTagTable: shouldTagTable, | ||
| isTOC: isTOC | ||
| }; |
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.
This PR is titled/described as adding accessibility tagging, but it also changes the published package name and bumps the version from 0.2.23 to 2.1.0. That’s a significant distribution/API change that should either be called out in the PR description/release notes or split into a separate PR to keep the change set scoped.