Skip to content

Commit

Permalink
Merge branch 'develop' into dependabot/docker/golang-2e83858
Browse files Browse the repository at this point in the history
  • Loading branch information
chocolatkey authored Feb 1, 2025
2 parents 3b04fe0 + f3dc16e commit a21833c
Show file tree
Hide file tree
Showing 9 changed files with 63 additions and 14 deletions.
29 changes: 26 additions & 3 deletions pkg/manifest/a11y.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ type A11y struct {
AccessModesSufficient [][]A11yPrimaryAccessMode `json:"accessModeSufficient,omitempty"` // A list of single or combined accessModes that are sufficient to understand all the intellectual content of a resource.
Features []A11yFeature `json:"feature,omitempty"` // Content features of the resource, such as accessible media, alternatives and supported enhancements for accessibility.
Hazards []A11yHazard `json:"hazard,omitempty"` // A characteristic of the described resource that is physiologically dangerous to some users.
Exemptions []A11yExemption `json:"exemption,omitempty"` // Justifications for non-conformance based on exemptions in a given jurisdiction.
}

// NewA11y creates a new empty A11y.
Expand All @@ -29,6 +30,7 @@ func NewA11y() A11y {
AccessModesSufficient: [][]A11yPrimaryAccessMode{},
Features: []A11yFeature{},
Hazards: []A11yHazard{},
Exemptions: []A11yExemption{},
}
}

Expand Down Expand Up @@ -130,6 +132,12 @@ func A11yFromJSON(rawJSON map[string]interface{}) (*A11y, error) {
}
a.Hazards = A11yHazardsFromStrings(hazards)

examptions, err := parseSliceOrString(rawJSON["exemption"], true)
if err != nil {
return nil, errors.Wrap(err, "failed unmarshalling 'exemption'")
}
a.Exemptions = A11yExemptionsFromStrings(examptions)

return a, nil
}

Expand Down Expand Up @@ -275,9 +283,9 @@ const (
// The work includes an index to the content.
A11yFeatureIndex A11yFeature = "index"

// The work includes equivalent print page numbers. This setting is most commonly used
// with ebooks for which there is a print equivalent.
A11yFeaturePrintPageNumbers A11yFeature = "printPageNumbers"
// The resource includes a means of navigating to static page break locations.
// The most common way of providing page navigation in digital publications is through a page list.
A11yFeaturePageNavigation A11yFeature = "pageNavigation"

// The reading order of the content is clearly defined in the markup
// (e.g., figures, sidebars and other secondary content has been marked up to allow it
Expand Down Expand Up @@ -433,6 +441,21 @@ func A11yHazardsFromStrings(strings []string) []A11yHazard {
})
}

// A11yExemption is a justification for non-conformance based on an exemption in a given jurisdiction.
type A11yExemption string

const (
A11yExemptionEAASisproportionateBurden A11yExemption = "eaa-disproportionate-burden"
A11yExemptionEAAFundamentalAlteration A11yExemption = "eaa-fundamental-alteration"
A11yExemptionEAAMicroenterprise A11yExemption = "eaa-microenterprise"
)

func A11yExemptionsFromStrings(strings []string) []A11yExemption {
return fromStrings(strings, func(str string) A11yExemption {
return A11yExemption(str)
})
}

func fromStrings[T any](strings []string, transform func(string) T) []T {
res := make([]T, 0, len(strings))
for _, s := range strings {
Expand Down
14 changes: 12 additions & 2 deletions pkg/manifest/a11y_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ func TestA11yUnmarshalFullJSON(t *testing.T) {
"accessMode": ["auditory", "chartOnVisual"],
"accessModeSufficient": [["visual", "tactile"]],
"feature": ["readingOrder", "alternativeText"],
"hazard": ["flashing", "motionSimulation"]
"hazard": ["flashing", "motionSimulation"],
"exemption": ["eaa-fundamental-alteration", "eaa-microenterprise"]
}`), &m))
assert.Equal(t, A11y{
ConformsTo: []A11yProfile{
Expand Down Expand Up @@ -57,6 +58,10 @@ func TestA11yUnmarshalFullJSON(t *testing.T) {
A11yHazardFlashing,
A11yHazardMotionSimulation,
},
Exemptions: []A11yExemption{
A11yExemptionEAAFundamentalAlteration,
A11yExemptionEAAMicroenterprise,
},
}, m, "unmarshalled JSON object should be equal to A11y object")
}

Expand Down Expand Up @@ -101,6 +106,7 @@ func TestA11yMarshalMinimalJSON(t *testing.T) {
AccessModesSufficient: [][]A11yPrimaryAccessMode{},
Features: []A11yFeature{},
Hazards: []A11yHazard{},
Exemptions: []A11yExemption{},
}
data, err := json.Marshal(m)
assert.NoError(t, err)
Expand Down Expand Up @@ -139,12 +145,16 @@ func TestA11yMarshalFullJSON(t *testing.T) {
A11yHazardFlashing,
A11yHazardMotionSimulation,
},
Exemptions: []A11yExemption{
A11yExemptionEAAFundamentalAlteration,
A11yExemptionEAAMicroenterprise,
},
}
data, err := json.Marshal(m)
assert.NoError(t, err)
assert.Equal(
t,
data,
[]byte(`{"conformsTo":["http://www.idpf.org/epub/a11y/accessibility-20170105.html#wcag-a","https://profile2"],"certification":{"certifiedBy":"company1","credential":"credential1","report":"https://report1"},"summary":"Summary","accessMode":["auditory","chartOnVisual"],"accessModeSufficient":[["auditory"],["visual","tactile"],["visual"]],"feature":["readingOrder","alternativeText"],"hazard":["flashing","motionSimulation"]}`),
[]byte(`{"conformsTo":["http://www.idpf.org/epub/a11y/accessibility-20170105.html#wcag-a","https://profile2"],"certification":{"certifiedBy":"company1","credential":"credential1","report":"https://report1"},"summary":"Summary","accessMode":["auditory","chartOnVisual"],"accessModeSufficient":[["auditory"],["visual","tactile"],["visual"]],"feature":["readingOrder","alternativeText"],"hazard":["flashing","motionSimulation"],"exemption":["eaa-fundamental-alteration","eaa-microenterprise"]}`),
)
}
10 changes: 10 additions & 0 deletions pkg/parser/epub/metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -646,6 +646,7 @@ func (m PubMetadataAdapter) Accessibility() *manifest.A11y {
a11y.AccessModesSufficient = m.a11yAccessModesSufficient()
a11y.Features = m.a11yFeatures()
a11y.Hazards = m.a11yHazards()
a11y.Exemptions = m.a11yExemptions()

if a11y.IsEmpty() {
return nil
Expand Down Expand Up @@ -785,6 +786,15 @@ func (m PubMetadataAdapter) a11yHazards() []manifest.A11yHazard {
return hazards
}

func (m PubMetadataAdapter) a11yExemptions() []manifest.A11yExemption {
values := m.Values(VocabularyA11Y + "exemption")
hazards := make([]manifest.A11yExemption, len(values))
for i, v := range values {
hazards[i] = manifest.A11yExemption(v)
}
return hazards
}

func (m *PubMetadataAdapter) seedBelongsToData() {
if m._belongsToSeeded {
return
Expand Down
2 changes: 2 additions & 0 deletions pkg/parser/epub/metadata_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,7 @@ func TestMetadataEPUB2Accessibility(t *testing.T) {
}
e.Features = []manifest.A11yFeature{manifest.A11yFeatureStructuralNavigation, manifest.A11yFeatureAlternativeText}
e.Hazards = []manifest.A11yHazard{manifest.A11yHazardMotionSimulation, manifest.A11yHazardNoSoundHazard}
e.Exemptions = []manifest.A11yExemption{manifest.A11yExemptionEAAMicroenterprise, manifest.A11yExemptionEAAFundamentalAlteration}
assert.Equal(t, &e, m.Accessibility)
assert.Nil(t, m.OtherMetadata["accessibility"])
}
Expand All @@ -345,6 +346,7 @@ func TestMetadataEPUB3Accessibility(t *testing.T) {
}
e.Features = []manifest.A11yFeature{manifest.A11yFeatureStructuralNavigation, manifest.A11yFeatureAlternativeText}
e.Hazards = []manifest.A11yHazard{manifest.A11yHazardMotionSimulation, manifest.A11yHazardNoSoundHazard}
e.Exemptions = []manifest.A11yExemption{manifest.A11yExemptionEAAMicroenterprise, manifest.A11yExemptionEAAFundamentalAlteration}
assert.Equal(t, &e, m.Accessibility)
assert.Nil(t, m.OtherMetadata["accessibility"])
}
Expand Down
10 changes: 4 additions & 6 deletions pkg/parser/epub/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,14 +111,13 @@ func parseNavigationData(packageDocument PackageDocument, fetcher fetcher.Fetche
if ncxItem == nil {
return
}
ncxPath := packageDocument.Path.Resolve(ncxItem.Href)
n, nerr := fetcher.Get(manifest.Link{Href: manifest.NewHREF(ncxPath)}).ReadAsXML(map[string]string{
n, nerr := fetcher.Get(manifest.Link{Href: manifest.NewHREF(ncxItem.Href)}).ReadAsXML(map[string]string{
NamespaceNCX: "ncx",
})
if nerr != nil {
return
}
ret = ParseNCX(n, ncxPath)
ret = ParseNCX(n, ncxItem.Href)
} else {
var navItem *Item
for _, v := range packageDocument.Manifest {
Expand All @@ -135,15 +134,14 @@ func parseNavigationData(packageDocument PackageDocument, fetcher fetcher.Fetche
if navItem == nil {
return
}
navPath := packageDocument.Path.Resolve(navItem.Href)
n, errx := fetcher.Get(manifest.Link{Href: manifest.NewHREF(navPath)}).ReadAsXML(map[string]string{
n, errx := fetcher.Get(manifest.Link{Href: manifest.NewHREF(navItem.Href)}).ReadAsXML(map[string]string{
NamespaceXHTML: "html",
NamespaceOPS: "epub",
})
if errx != nil {
return
}
ret = ParseNavDoc(n, navPath)
ret = ParseNavDoc(n, navItem.Href)
}
return
}
Expand Down
3 changes: 3 additions & 0 deletions pkg/parser/epub/testdata/package/accessibility-epub2.opf
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@
<meta name="a11y:certifiedBy" content="Accessibility Testers Group"/>
<meta name="a11y:certifierCredential" content="DAISY OK"/>
<meta name="a11y:certifierReport" content="https://example.com/a11y-report/"/>

<meta property="a11y:exemption">eaa-microenterprise</meta>
<meta property="a11y:exemption">eaa-fundamental-alteration</meta>
</metadata>
<manifest>
<item id="titlepage" href="titlepage.xhtml"/>
Expand Down
3 changes: 3 additions & 0 deletions pkg/parser/epub/testdata/package/accessibility-epub3.opf
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@
<link rel="a11y:certifierReport" refines="#certifier2" href="https://example.com/fakereport"/>
<link rel="a11y:certifierReport" refines="#certifier" href="https://example.com/a11y-report/"/>

<meta property="a11y:exemption">eaa-microenterprise</meta>
<meta property="a11y:exemption">eaa-fundamental-alteration</meta>

</metadata>
<manifest>
<item id="titlepage" href="titlepage.xhtml"/>
Expand Down
4 changes: 2 additions & 2 deletions pkg/streamer/a11y_infer.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,13 +114,13 @@ func inferA11yMetadataFromManifest(mf manifest.Manifest) *manifest.A11y {
}
}

if mf.TableOfContents != nil && len(mf.TableOfContents) > 0 {
if len(mf.TableOfContents) > 0 {
addFeature(manifest.A11yFeatureTableOfContents)
}

if mf.ConformsTo(manifest.ProfileEPUB) {
if _, hasPageList := mf.Subcollections["pageList"]; hasPageList {
addFeature(manifest.A11yFeaturePrintPageNumbers)
addFeature(manifest.A11yFeaturePageNavigation)
}

for _, link := range allResources {
Expand Down
2 changes: 1 addition & 1 deletion pkg/streamer/a11y_infer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ func TestInferFeaturePageList(t *testing.T) {
},
ReadingOrder: []manifest.Link{newLink(mediatype.HTML, "html")},
}
assertFeature(t, m, manifest.A11yFeaturePrintPageNumbers)
assertFeature(t, m, manifest.A11yFeaturePageNavigation)
}

// If the publication contains any resource with MathML (check for the presence
Expand Down

0 comments on commit a21833c

Please sign in to comment.