@readium/guided-navigation 1.1.3 → 1.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/a11y.js +1 -1
- package/dist/converter.js +1 -1
- package/dist/elementHandlers.js +1 -1
- package/dist/emptyPairs.js +1 -0
- package/dist/object.js +1 -1
- package/dist/prescan.js +1 -1
- package/dist/roles.js +1 -1
- package/dist/text.js +1 -1
- package/dist/textrefFragment.js +1 -1
- package/fixtures/ROLES_COVERAGE.md +6 -5
- package/fixtures/abbreviation-acronym-html-native/gnd.json +9 -0
- package/fixtures/abbreviation-acronym-html-native/input.html +1 -0
- package/fixtures/abbreviation-acronym-html-native/meta.json +11 -0
- package/fixtures/abbreviation-before-formatting/gnd.json +9 -0
- package/fixtures/abbreviation-before-formatting/input.html +1 -0
- package/fixtures/abbreviation-before-formatting/meta.json +11 -0
- package/fixtures/abbreviation-before-image/gnd.json +24 -0
- package/fixtures/abbreviation-before-image/input.html +1 -0
- package/fixtures/abbreviation-before-image/meta.json +12 -0
- package/fixtures/abbreviation-html-native/gnd.json +9 -0
- package/fixtures/abbreviation-html-native/input.html +1 -0
- package/fixtures/abbreviation-html-native/meta.json +11 -0
- package/fixtures/abbreviation-language/gnd.json +9 -0
- package/fixtures/abbreviation-language/input.html +1 -0
- package/fixtures/abbreviation-language/meta.json +11 -0
- package/fixtures/abbreviation-line-break/gnd.json +9 -0
- package/fixtures/abbreviation-line-break/input.html +1 -0
- package/fixtures/abbreviation-line-break/meta.json +11 -0
- package/fixtures/abbreviation-nested/gnd.json +9 -0
- package/fixtures/abbreviation-nested/input.html +1 -0
- package/fixtures/abbreviation-nested/meta.json +11 -0
- package/fixtures/abbreviation-nested-emphasis/gnd.json +9 -0
- package/fixtures/abbreviation-nested-emphasis/input.html +1 -0
- package/fixtures/abbreviation-nested-emphasis/meta.json +11 -0
- package/fixtures/abbreviation-nested-term/gnd.json +21 -0
- package/fixtures/abbreviation-nested-term/input.html +1 -0
- package/fixtures/abbreviation-nested-term/meta.json +12 -0
- package/fixtures/abbreviation-nested-term-punctuation/gnd.json +26 -0
- package/fixtures/abbreviation-nested-term-punctuation/input.html +1 -0
- package/fixtures/abbreviation-nested-term-punctuation/meta.json +12 -0
- package/fixtures/abbreviation-no-title/gnd.json +8 -0
- package/fixtures/abbreviation-no-title/input.html +1 -0
- package/fixtures/abbreviation-no-title/meta.json +11 -0
- package/fixtures/abbreviation-spanning-terms/gnd.json +33 -0
- package/fixtures/abbreviation-spanning-terms/input.html +1 -0
- package/fixtures/abbreviation-spanning-terms/meta.json +12 -0
- package/fixtures/abbreviation-with-image/gnd.json +24 -0
- package/fixtures/abbreviation-with-image/input.html +1 -0
- package/fixtures/abbreviation-with-image/meta.json +12 -0
- package/fixtures/abbreviation-with-svg-and-math/gnd.json +39 -0
- package/fixtures/abbreviation-with-svg-and-math/input.html +1 -0
- package/fixtures/abbreviation-with-svg-and-math/meta.json +13 -0
- package/fixtures/biblioref-target-descendant-ids/gnd.json +90 -0
- package/fixtures/biblioref-target-descendant-ids/input.html +1 -0
- package/fixtures/biblioref-target-descendant-ids/meta.json +14 -0
- package/fixtures/biblioref-target-in-bibliography-role-aria/gnd.json +59 -0
- package/fixtures/biblioref-target-in-bibliography-role-aria/input.html +6 -0
- package/fixtures/biblioref-target-in-bibliography-role-aria/meta.json +14 -0
- package/fixtures/biblioref-target-mixed-content/gnd.json +63 -0
- package/fixtures/biblioref-target-mixed-content/input.html +1 -0
- package/fixtures/biblioref-target-mixed-content/meta.json +11 -0
- package/fixtures/glossref-sole-content/gnd.json +70 -0
- package/fixtures/glossref-sole-content/input.html +5 -0
- package/fixtures/glossref-sole-content/meta.json +14 -0
- package/fixtures/glossref-target-in-glossary-role-aria/gnd.json +76 -0
- package/fixtures/glossref-target-in-glossary-role-aria/input.html +5 -0
- package/fixtures/glossref-target-in-glossary-role-aria/meta.json +14 -0
- package/fixtures/glossref-target-percent-encoded/gnd.json +68 -0
- package/fixtures/glossref-target-percent-encoded/input.html +1 -0
- package/fixtures/glossref-target-percent-encoded/meta.json +14 -0
- package/fixtures/manifest.json +360 -0
- package/fixtures/noteref-after-closing-straight-quote/gnd.json +32 -0
- package/fixtures/noteref-after-closing-straight-quote/input.html +1 -0
- package/fixtures/noteref-after-closing-straight-quote/meta.json +13 -0
- package/fixtures/noteref-after-closing-straight-quote-split/gnd.json +38 -0
- package/fixtures/noteref-after-closing-straight-quote-split/input.html +1 -0
- package/fixtures/noteref-after-closing-straight-quote-split/meta.json +12 -0
- package/fixtures/noteref-enclosed-across-formatting/gnd.json +32 -0
- package/fixtures/noteref-enclosed-across-formatting/input.html +1 -0
- package/fixtures/noteref-enclosed-across-formatting/meta.json +13 -0
- package/fixtures/noteref-enclosed-adjacent-pairs/gnd.json +108 -0
- package/fixtures/noteref-enclosed-adjacent-pairs/input.html +1 -0
- package/fixtures/noteref-enclosed-adjacent-pairs/meta.json +13 -0
- package/fixtures/noteref-enclosed-adjacent-text/gnd.json +34 -0
- package/fixtures/noteref-enclosed-adjacent-text/input.html +1 -0
- package/fixtures/noteref-enclosed-adjacent-text/meta.json +13 -0
- package/fixtures/noteref-enclosed-before-formatting/gnd.json +34 -0
- package/fixtures/noteref-enclosed-before-formatting/input.html +1 -0
- package/fixtures/noteref-enclosed-before-formatting/meta.json +13 -0
- package/fixtures/noteref-enclosed-guillemets-french/gnd.json +103 -0
- package/fixtures/noteref-enclosed-guillemets-french/input.html +1 -0
- package/fixtures/noteref-enclosed-guillemets-french/meta.json +13 -0
- package/fixtures/noteref-enclosed-quotes-chinese/gnd.json +47 -0
- package/fixtures/noteref-enclosed-quotes-chinese/input.html +1 -0
- package/fixtures/noteref-enclosed-quotes-chinese/meta.json +13 -0
- package/fixtures/noteref-enclosed-quotes-german/gnd.json +124 -0
- package/fixtures/noteref-enclosed-quotes-german/input.html +1 -0
- package/fixtures/noteref-enclosed-quotes-german/meta.json +13 -0
- package/fixtures/noteref-enclosed-quotes-swedish/gnd.json +70 -0
- package/fixtures/noteref-enclosed-quotes-swedish/input.html +1 -0
- package/fixtures/noteref-enclosed-quotes-swedish/meta.json +13 -0
- package/fixtures/noteref-enclosed-straight-quotes/gnd.json +32 -0
- package/fixtures/noteref-enclosed-straight-quotes/input.html +1 -0
- package/fixtures/noteref-enclosed-straight-quotes/meta.json +13 -0
- package/fixtures/noteref-in-lone-block/gnd.json +29 -0
- package/fixtures/noteref-in-lone-block/input.html +1 -0
- package/fixtures/noteref-in-lone-block/meta.json +12 -0
- package/fixtures/noteref-target-malformed-escape/gnd.json +32 -0
- package/fixtures/noteref-target-malformed-escape/input.html +1 -0
- package/fixtures/noteref-target-malformed-escape/meta.json +13 -0
- package/fixtures/noteref-target-percent-encoded/gnd.json +32 -0
- package/fixtures/noteref-target-percent-encoded/input.html +1 -0
- package/fixtures/noteref-target-percent-encoded/meta.json +13 -0
- package/fixtures/table-cell-abbreviation/gnd.json +55 -0
- package/fixtures/table-cell-abbreviation/input.html +4 -0
- package/fixtures/table-cell-abbreviation/meta.json +15 -0
- package/fixtures/table-cell-noteref/gnd.json +77 -0
- package/fixtures/table-cell-noteref/input.html +5 -0
- package/fixtures/table-cell-noteref/meta.json +16 -0
- package/package.json +1 -1
- package/src/a11y.ts +4 -4
- package/src/converter.ts +112 -25
- package/src/elementHandlers.ts +64 -11
- package/src/emptyPairs.ts +74 -0
- package/src/object.ts +4 -0
- package/src/prescan.ts +2 -1
- package/src/roles.ts +2 -0
- package/src/text.ts +3 -1
- package/src/textrefFragment.ts +9 -1
- package/types/src/converter.d.ts +4 -0
- package/types/src/elementHandlers.d.ts +1 -0
- package/types/src/emptyPairs.d.ts +3 -0
- package/types/src/text.d.ts +1 -0
- package/types/src/textrefFragment.d.ts +4 -0
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
{
|
|
2
|
+
"id": "noteref-enclosed-straight-quotes",
|
|
3
|
+
"description": "Straight quotes left empty by a noteref are removed from plain text",
|
|
4
|
+
"role": "noteref",
|
|
5
|
+
"rolesCovered": [
|
|
6
|
+
"noteref",
|
|
7
|
+
"footnote",
|
|
8
|
+
"aside",
|
|
9
|
+
"paragraph"
|
|
10
|
+
],
|
|
11
|
+
"sourceRef": "https://github.com/readium/guided-navigation/blob/main/roles.md",
|
|
12
|
+
"inputKind": "fragment"
|
|
13
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
{
|
|
2
|
+
"children": [
|
|
3
|
+
{
|
|
4
|
+
"id": "n",
|
|
5
|
+
"children": [
|
|
6
|
+
{
|
|
7
|
+
"role": [
|
|
8
|
+
"aside",
|
|
9
|
+
"footnote"
|
|
10
|
+
],
|
|
11
|
+
"text": {
|
|
12
|
+
"plain": "Note."
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
],
|
|
16
|
+
"role": [
|
|
17
|
+
"noteref"
|
|
18
|
+
],
|
|
19
|
+
"text": {
|
|
20
|
+
"plain": "1"
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
],
|
|
24
|
+
"text": {
|
|
25
|
+
"plain": "Text here.",
|
|
26
|
+
"ssml": "Text \"<readium:noteref id=\"n\" />\" here.",
|
|
27
|
+
"language": "en"
|
|
28
|
+
}
|
|
29
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
<div>Text "<a role="doc-noteref" href="#n">1</a>" here.</div><aside id="n" role="doc-footnote">Note.</aside>
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
{
|
|
2
|
+
"id": "noteref-in-lone-block",
|
|
3
|
+
"description": "A lone roleless block's text is kept alongside the noteref it embeds",
|
|
4
|
+
"role": "noteref",
|
|
5
|
+
"rolesCovered": [
|
|
6
|
+
"noteref",
|
|
7
|
+
"footnote",
|
|
8
|
+
"aside"
|
|
9
|
+
],
|
|
10
|
+
"sourceRef": "https://github.com/readium/guided-navigation/blob/main/roles.md",
|
|
11
|
+
"inputKind": "fragment"
|
|
12
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
{
|
|
2
|
+
"children": [
|
|
3
|
+
{
|
|
4
|
+
"id": "note%E0%A4",
|
|
5
|
+
"children": [
|
|
6
|
+
{
|
|
7
|
+
"role": [
|
|
8
|
+
"aside",
|
|
9
|
+
"footnote"
|
|
10
|
+
],
|
|
11
|
+
"text": {
|
|
12
|
+
"plain": "Note."
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
],
|
|
16
|
+
"role": [
|
|
17
|
+
"noteref"
|
|
18
|
+
],
|
|
19
|
+
"text": {
|
|
20
|
+
"plain": "1"
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
],
|
|
24
|
+
"role": [
|
|
25
|
+
"paragraph"
|
|
26
|
+
],
|
|
27
|
+
"text": {
|
|
28
|
+
"plain": "Text.",
|
|
29
|
+
"ssml": "Text<readium:noteref id=\"note%E0%A4\" />.",
|
|
30
|
+
"language": "en"
|
|
31
|
+
}
|
|
32
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
<p>Text<a role="doc-noteref" href="#note%E0%A4">1</a>.</p><aside id="note%E0%A4" role="doc-footnote">Note.</aside>
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
{
|
|
2
|
+
"id": "noteref-target-malformed-escape",
|
|
3
|
+
"description": "A noteref whose href has a malformed percent-escape falls back to the fragment as written",
|
|
4
|
+
"role": "noteref",
|
|
5
|
+
"rolesCovered": [
|
|
6
|
+
"noteref",
|
|
7
|
+
"footnote",
|
|
8
|
+
"aside",
|
|
9
|
+
"paragraph"
|
|
10
|
+
],
|
|
11
|
+
"sourceRef": "https://github.com/readium/guided-navigation/blob/main/roles.md",
|
|
12
|
+
"inputKind": "fragment"
|
|
13
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
{
|
|
2
|
+
"children": [
|
|
3
|
+
{
|
|
4
|
+
"id": "note-café",
|
|
5
|
+
"children": [
|
|
6
|
+
{
|
|
7
|
+
"role": [
|
|
8
|
+
"aside",
|
|
9
|
+
"footnote"
|
|
10
|
+
],
|
|
11
|
+
"text": {
|
|
12
|
+
"plain": "Note."
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
],
|
|
16
|
+
"role": [
|
|
17
|
+
"noteref"
|
|
18
|
+
],
|
|
19
|
+
"text": {
|
|
20
|
+
"plain": "1"
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
],
|
|
24
|
+
"role": [
|
|
25
|
+
"paragraph"
|
|
26
|
+
],
|
|
27
|
+
"text": {
|
|
28
|
+
"plain": "Text.",
|
|
29
|
+
"ssml": "Text<readium:noteref id=\"note-café\" />.",
|
|
30
|
+
"language": "en"
|
|
31
|
+
}
|
|
32
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
<p>Text<a role="doc-noteref" href="#note-caf%C3%A9">1</a>.</p><aside id="note-café" role="doc-footnote">Note.</aside>
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
{
|
|
2
|
+
"id": "noteref-target-percent-encoded",
|
|
3
|
+
"description": "A noteref whose href is percent-encoded still finds and embeds its footnote, which isn't output again at its own location",
|
|
4
|
+
"role": "noteref",
|
|
5
|
+
"rolesCovered": [
|
|
6
|
+
"noteref",
|
|
7
|
+
"footnote",
|
|
8
|
+
"aside",
|
|
9
|
+
"paragraph"
|
|
10
|
+
],
|
|
11
|
+
"sourceRef": "https://github.com/readium/guided-navigation/blob/main/roles.md",
|
|
12
|
+
"inputKind": "fragment"
|
|
13
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
{
|
|
2
|
+
"children": [
|
|
3
|
+
{
|
|
4
|
+
"children": [
|
|
5
|
+
{
|
|
6
|
+
"role": [
|
|
7
|
+
"columnheader"
|
|
8
|
+
],
|
|
9
|
+
"text": {
|
|
10
|
+
"plain": "Body"
|
|
11
|
+
}
|
|
12
|
+
},
|
|
13
|
+
{
|
|
14
|
+
"role": [
|
|
15
|
+
"columnheader"
|
|
16
|
+
],
|
|
17
|
+
"text": {
|
|
18
|
+
"plain": "Role"
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
],
|
|
22
|
+
"role": [
|
|
23
|
+
"row"
|
|
24
|
+
]
|
|
25
|
+
},
|
|
26
|
+
{
|
|
27
|
+
"children": [
|
|
28
|
+
{
|
|
29
|
+
"role": [
|
|
30
|
+
"rowheader"
|
|
31
|
+
],
|
|
32
|
+
"text": {
|
|
33
|
+
"ssml": "<sub alias=\"World Health Organization\">WHO</sub>",
|
|
34
|
+
"language": "en"
|
|
35
|
+
}
|
|
36
|
+
},
|
|
37
|
+
{
|
|
38
|
+
"role": [
|
|
39
|
+
"cell"
|
|
40
|
+
],
|
|
41
|
+
"text": {
|
|
42
|
+
"ssml": "Leads the <sub alias=\"International Health Regulations\">IHR</sub> work",
|
|
43
|
+
"language": "en"
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
],
|
|
47
|
+
"role": [
|
|
48
|
+
"row"
|
|
49
|
+
]
|
|
50
|
+
}
|
|
51
|
+
],
|
|
52
|
+
"role": [
|
|
53
|
+
"table"
|
|
54
|
+
]
|
|
55
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
{
|
|
2
|
+
"id": "table-cell-abbreviation",
|
|
3
|
+
"description": "An abbr inside a row header and a data cell stays a sub in that cell's own text",
|
|
4
|
+
"role": "table",
|
|
5
|
+
"rolesCovered": [
|
|
6
|
+
"table",
|
|
7
|
+
"row",
|
|
8
|
+
"columnheader",
|
|
9
|
+
"rowheader",
|
|
10
|
+
"cell",
|
|
11
|
+
"abbreviation"
|
|
12
|
+
],
|
|
13
|
+
"sourceRef": "https://github.com/readium/guided-navigation/blob/main/roles.md",
|
|
14
|
+
"inputKind": "fragment"
|
|
15
|
+
}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
{
|
|
2
|
+
"children": [
|
|
3
|
+
{
|
|
4
|
+
"children": [
|
|
5
|
+
{
|
|
6
|
+
"role": [
|
|
7
|
+
"columnheader"
|
|
8
|
+
],
|
|
9
|
+
"text": {
|
|
10
|
+
"plain": "Name"
|
|
11
|
+
}
|
|
12
|
+
},
|
|
13
|
+
{
|
|
14
|
+
"role": [
|
|
15
|
+
"columnheader"
|
|
16
|
+
],
|
|
17
|
+
"text": {
|
|
18
|
+
"plain": "Role"
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
],
|
|
22
|
+
"role": [
|
|
23
|
+
"row"
|
|
24
|
+
]
|
|
25
|
+
},
|
|
26
|
+
{
|
|
27
|
+
"children": [
|
|
28
|
+
{
|
|
29
|
+
"role": [
|
|
30
|
+
"rowheader"
|
|
31
|
+
],
|
|
32
|
+
"text": {
|
|
33
|
+
"plain": "Ada"
|
|
34
|
+
}
|
|
35
|
+
},
|
|
36
|
+
{
|
|
37
|
+
"children": [
|
|
38
|
+
{
|
|
39
|
+
"id": "n1",
|
|
40
|
+
"children": [
|
|
41
|
+
{
|
|
42
|
+
"role": [
|
|
43
|
+
"aside",
|
|
44
|
+
"footnote"
|
|
45
|
+
],
|
|
46
|
+
"text": {
|
|
47
|
+
"plain": "First published in 1843."
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
],
|
|
51
|
+
"role": [
|
|
52
|
+
"noteref"
|
|
53
|
+
],
|
|
54
|
+
"text": {
|
|
55
|
+
"plain": "1"
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
],
|
|
59
|
+
"role": [
|
|
60
|
+
"cell"
|
|
61
|
+
],
|
|
62
|
+
"text": {
|
|
63
|
+
"plain": "Engineer and writer",
|
|
64
|
+
"ssml": "Engineer<readium:noteref id=\"n1\" /> and writer",
|
|
65
|
+
"language": "en"
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
],
|
|
69
|
+
"role": [
|
|
70
|
+
"row"
|
|
71
|
+
]
|
|
72
|
+
}
|
|
73
|
+
],
|
|
74
|
+
"role": [
|
|
75
|
+
"table"
|
|
76
|
+
]
|
|
77
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
{
|
|
2
|
+
"id": "table-cell-noteref",
|
|
3
|
+
"description": "A noteref inside a data cell becomes a placeholder in that cell's own text, its footnote embedded",
|
|
4
|
+
"role": "table",
|
|
5
|
+
"rolesCovered": [
|
|
6
|
+
"table",
|
|
7
|
+
"row",
|
|
8
|
+
"columnheader",
|
|
9
|
+
"rowheader",
|
|
10
|
+
"cell",
|
|
11
|
+
"noteref",
|
|
12
|
+
"footnote"
|
|
13
|
+
],
|
|
14
|
+
"sourceRef": "https://github.com/readium/guided-navigation/blob/main/roles.md",
|
|
15
|
+
"inputKind": "fragment"
|
|
16
|
+
}
|
package/package.json
CHANGED
package/src/a11y.ts
CHANGED
|
@@ -93,7 +93,7 @@ export function extractNodeAria(el: Element): [string | null, boolean, string] {
|
|
|
93
93
|
}
|
|
94
94
|
|
|
95
95
|
// 2.C
|
|
96
|
-
const label = (el.getAttribute("aria-label") ?? "").trim();
|
|
96
|
+
const label = normalizeWhitespace(el.getAttribute("aria-label") ?? "", true).trim();
|
|
97
97
|
if (label) {
|
|
98
98
|
return [label, true, nodeLanguage(el)];
|
|
99
99
|
}
|
|
@@ -121,10 +121,10 @@ export function extractNodeAria(el: Element): [string | null, boolean, string] {
|
|
|
121
121
|
// 2.D (partial support)
|
|
122
122
|
const tagName = el.tagName.toLowerCase();
|
|
123
123
|
if (tagName === "img") {
|
|
124
|
-
const alt = (el.getAttribute("alt") ?? "").trim();
|
|
124
|
+
const alt = normalizeWhitespace(el.getAttribute("alt") ?? "", true).trim();
|
|
125
125
|
if (alt) return [alt, true, nodeLanguage(el)];
|
|
126
126
|
// 2.I fallback for images: the title attribute
|
|
127
|
-
const title = (el.getAttribute("title") ?? "").trim();
|
|
127
|
+
const title = normalizeWhitespace(el.getAttribute("title") ?? "", true).trim();
|
|
128
128
|
if (title) return [title, true, nodeLanguage(el)];
|
|
129
129
|
} else if (tagName === "svg") {
|
|
130
130
|
// The accessible name of an SVG comes from its <title> child
|
|
@@ -135,7 +135,7 @@ export function extractNodeAria(el: Element): [string | null, boolean, string] {
|
|
|
135
135
|
}
|
|
136
136
|
} else if (tagName === "math") {
|
|
137
137
|
// MathML Core's spoken-form fallback (not part of the ARIA AccName algorithm)
|
|
138
|
-
const alttext = (el.getAttribute("alttext") ?? "").trim();
|
|
138
|
+
const alttext = normalizeWhitespace(el.getAttribute("alttext") ?? "", true).trim();
|
|
139
139
|
if (alttext) return [alttext, true, nodeLanguage(el)];
|
|
140
140
|
}
|
|
141
141
|
|
package/src/converter.ts
CHANGED
|
@@ -14,9 +14,9 @@ import {
|
|
|
14
14
|
ctxEqual,
|
|
15
15
|
normalizeWhitespace,
|
|
16
16
|
} from "./text.ts";
|
|
17
|
-
import { ssmlAttrEscape, ssmlTextEscape
|
|
17
|
+
import { ssmlAttrEscape, ssmlTextEscape } from "@readium/helpers";
|
|
18
18
|
import { type ObjBuilder, NavObject, isEmptyObj, finalizeToGuidedNavigationObject, setDescription } from "./object.ts";
|
|
19
|
-
import { type GndMediaType, isInlineTag, sniffMediaType } from "./dom.ts";
|
|
19
|
+
import { type GndMediaType, isAncestorOf, isInlineTag, sniffMediaType } from "./dom.ts";
|
|
20
20
|
import { declaredLanguage, nodeLanguage, sameLanguage } from "./language.ts";
|
|
21
21
|
import { encodeDomRangeFragment, encodeTextFragmentDirective } from "./textrefFragment.ts";
|
|
22
22
|
import { resolveRefs } from "./href.ts";
|
|
@@ -26,7 +26,8 @@ import { textFragmentDirectiveFor } from "./textFragmentGenerator.ts";
|
|
|
26
26
|
import { type GndGenerationOptions, normalizeTextrefOptions } from "./options.ts";
|
|
27
27
|
import { IdAllocator } from "./idAllocator.ts";
|
|
28
28
|
import { prescan as prescanImpl } from "./prescan.ts";
|
|
29
|
-
import { pagebreak, noteref, link } from "./elementHandlers.ts";
|
|
29
|
+
import { pagebreak, noteref, reference, link } from "./elementHandlers.ts";
|
|
30
|
+
import { DROPPED, bindsToPrevious, removeDropped } from "./emptyPairs.ts";
|
|
30
31
|
|
|
31
32
|
const MATHML_NS = "http://www.w3.org/1998/Math/MathML";
|
|
32
33
|
|
|
@@ -79,6 +80,8 @@ export class Converter {
|
|
|
79
80
|
selectorRoot: Element | null = null;
|
|
80
81
|
// Prefixed onto every generated selector — see selectorGenerator.ts's rootAnchorSelector().
|
|
81
82
|
selectorRootAnchor: string | null = null;
|
|
83
|
+
// Converting a copy of content also output at its own location, which keeps its elements' ids.
|
|
84
|
+
copy = false;
|
|
82
85
|
|
|
83
86
|
private root = new NavObject();
|
|
84
87
|
private current = this.root;
|
|
@@ -129,6 +132,7 @@ export class Converter {
|
|
|
129
132
|
child.domRangeEnabled = this.domRangeEnabled;
|
|
130
133
|
child.textFragmentEnabled = this.textFragmentEnabled;
|
|
131
134
|
child.leafTextEnabled = this.leafTextEnabled;
|
|
135
|
+
child.copy = this.copy;
|
|
132
136
|
return child;
|
|
133
137
|
}
|
|
134
138
|
|
|
@@ -156,7 +160,8 @@ export class Converter {
|
|
|
156
160
|
|
|
157
161
|
resultBuilders(): ObjBuilder[] {
|
|
158
162
|
const res = this.root.finalize((el) => textrefForSelector(selectorForElement(el, this.selectorRoot, this.selectorRootAnchor), el));
|
|
159
|
-
|
|
163
|
+
// Text of its own, from a flow hoisted onto it, makes the root content too, not just a container.
|
|
164
|
+
if (!res.children || res.children.length === 0 || res.text) {
|
|
160
165
|
if (isEmptyObj(res)) return [];
|
|
161
166
|
return [res];
|
|
162
167
|
}
|
|
@@ -224,7 +229,8 @@ export class Converter {
|
|
|
224
229
|
}
|
|
225
230
|
|
|
226
231
|
if (tagName === "br") {
|
|
227
|
-
|
|
232
|
+
// Within an abbreviation's expansion, a line break is only visual.
|
|
233
|
+
if (!this.current.noText && !this.textContext(el).abbr) {
|
|
228
234
|
this.closeSegment();
|
|
229
235
|
this.segments.push({ kind: "break" });
|
|
230
236
|
this.flowEndsWithSpace = true;
|
|
@@ -239,8 +245,12 @@ export class Converter {
|
|
|
239
245
|
noteref(this, el, roles);
|
|
240
246
|
return true;
|
|
241
247
|
}
|
|
248
|
+
if (tagName === "a" && (roles.includes("glossref") || roles.includes("biblioref")) && el.getAttribute("href")) {
|
|
249
|
+
reference(this, el, roles, aria, ariaLanguage);
|
|
250
|
+
return true;
|
|
251
|
+
}
|
|
242
252
|
if (tagName === "a" && el.getAttribute("href")) {
|
|
243
|
-
// Any other link — backlink
|
|
253
|
+
// Any other link — a backlink, or a plain navigational
|
|
244
254
|
// link with no specific role (e.g. a TOC entry) — carries its href as
|
|
245
255
|
// textref. When it's the sole content of its enclosing block (the usual
|
|
246
256
|
// case for list items), the hoist rule promotes it onto that block;
|
|
@@ -423,6 +433,20 @@ export class Converter {
|
|
|
423
433
|
}
|
|
424
434
|
|
|
425
435
|
private textContext(node: Node): SSMLContext {
|
|
436
|
+
// An abbreviation's text is replaced by its expansion as a whole, so it wins over any formatting inside it.
|
|
437
|
+
// It applies only if all its text is in one object, so its alias is never repeated or misplaced.
|
|
438
|
+
// The outermost one wins, its expansion covering any nested inside it.
|
|
439
|
+
let abbr: SSMLContext | undefined;
|
|
440
|
+
for (let p = node.parentElement, enclosing = false; p; p = p.parentElement) {
|
|
441
|
+
const alias = abbreviationExpansion(p);
|
|
442
|
+
if (alias) {
|
|
443
|
+
if (!enclosing && Converter.containsObject(p)) break;
|
|
444
|
+
abbr = { lang: declaredLanguage(p), tag: "sub", attrs: { alias }, abbr: p };
|
|
445
|
+
}
|
|
446
|
+
if (p === this.current.el) enclosing = true;
|
|
447
|
+
if (enclosing && !Converter.isSoleContent(p)) break;
|
|
448
|
+
}
|
|
449
|
+
if (abbr) return abbr;
|
|
426
450
|
const ctx: SSMLContext = { lang: declaredLanguage(node.parentElement), tag: "" };
|
|
427
451
|
for (let p = node.parentElement; p && p !== this.current.el; p = p.parentElement) {
|
|
428
452
|
const [tag, attrs] = convertElementToSSMLTag(p.tagName.toLowerCase());
|
|
@@ -435,6 +459,30 @@ export class Converter {
|
|
|
435
459
|
return ctx;
|
|
436
460
|
}
|
|
437
461
|
|
|
462
|
+
private static containsObject(el: Element): boolean {
|
|
463
|
+
for (let c = el.firstElementChild; c; c = c.nextElementSibling) {
|
|
464
|
+
const tagName = c.tagName.toLowerCase();
|
|
465
|
+
const roles = extractNodeRoles(c);
|
|
466
|
+
if (skippedElements.has(tagName) || Converter.isPlaceholder(c, tagName, roles)) continue;
|
|
467
|
+
if (isBlockNode(tagName, roles) || Converter.containsObject(c)) return true;
|
|
468
|
+
}
|
|
469
|
+
return false;
|
|
470
|
+
}
|
|
471
|
+
|
|
472
|
+
// What head() embeds as a placeholder in the flow, rather than descending into.
|
|
473
|
+
private static isPlaceholder(el: Element, tagName: string, roles: GndRole[]): boolean {
|
|
474
|
+
if (roles.includes("pagebreak") || roles.includes("image") || roles.includes("math")) return true;
|
|
475
|
+
return ["img", "svg", "audio", "video"].includes(tagName) || (tagName === "a" && !!el.getAttribute("href"));
|
|
476
|
+
}
|
|
477
|
+
|
|
478
|
+
// Punctuation alongside doesn't count, e.g. the last period of <abbr><dfn>W.H.O</dfn>.</abbr>.
|
|
479
|
+
private static isSoleContent(el: Element): boolean {
|
|
480
|
+
for (let s = el.parentNode?.firstChild; s; s = s.nextSibling) {
|
|
481
|
+
if (s !== el && (s.nodeType === ELEMENT_NODE || (s.nodeType === TEXT_NODE && !/^[\s\p{P}]*$/u.test(s.nodeValue ?? "")))) return false;
|
|
482
|
+
}
|
|
483
|
+
return true;
|
|
484
|
+
}
|
|
485
|
+
|
|
438
486
|
private updateFlowSpace() {
|
|
439
487
|
if (this.textAcc.length > 0) {
|
|
440
488
|
this.flowEndsWithSpace = this.textAcc.endsWith(" ");
|
|
@@ -527,6 +575,34 @@ export class Converter {
|
|
|
527
575
|
break;
|
|
528
576
|
}
|
|
529
577
|
|
|
578
|
+
// An abbreviation's expansion is spoken once, so its pieces become one segment, followed by any object within it.
|
|
579
|
+
const merged: Segment[] = [];
|
|
580
|
+
for (let i = 0; i < segments.length; i++) {
|
|
581
|
+
const seg = segments[i];
|
|
582
|
+
const abbr = seg.kind === "text" ? seg.ctx!.abbr : undefined;
|
|
583
|
+
if (!abbr) {
|
|
584
|
+
merged.push(seg);
|
|
585
|
+
continue;
|
|
586
|
+
}
|
|
587
|
+
let text = seg.text!;
|
|
588
|
+
const within: Segment[] = [];
|
|
589
|
+
let pending: Segment[] = [];
|
|
590
|
+
for (let j = i + 1; j < segments.length; j++) {
|
|
591
|
+
const next = segments[j];
|
|
592
|
+
if (next.kind === "placeholder" && isAncestorOf(abbr, next.child!.el!)) {
|
|
593
|
+
pending.push(next);
|
|
594
|
+
continue;
|
|
595
|
+
}
|
|
596
|
+
if (next.kind !== "text" || next.ctx!.abbr !== abbr) break;
|
|
597
|
+
text += next.text!;
|
|
598
|
+
within.push(...pending);
|
|
599
|
+
pending = [];
|
|
600
|
+
i = j;
|
|
601
|
+
}
|
|
602
|
+
merged.push({ ...seg, text }, ...within);
|
|
603
|
+
}
|
|
604
|
+
segments = merged;
|
|
605
|
+
|
|
530
606
|
const hasText = segments.some((s) => s.kind === "text" && s.text!.trim() !== "");
|
|
531
607
|
if (!hasText) {
|
|
532
608
|
for (const child of pending) this.appendChild(child);
|
|
@@ -565,7 +641,7 @@ export class Converter {
|
|
|
565
641
|
if (needSSML) {
|
|
566
642
|
for (const seg of segments) {
|
|
567
643
|
if (seg.kind !== "placeholder") continue;
|
|
568
|
-
let id = seg.candidateID;
|
|
644
|
+
let id = this.copy ? undefined : seg.candidateID;
|
|
569
645
|
if (!id || !this.idAlloc.claim(id)) {
|
|
570
646
|
id = this.idAlloc.allocate(seg.tag!, (candidate) => this.ids.has(candidate));
|
|
571
647
|
}
|
|
@@ -590,7 +666,7 @@ export class Converter {
|
|
|
590
666
|
if (plainB.length > 0) {
|
|
591
667
|
const spaced = prevTrail || midSpace || lead;
|
|
592
668
|
if (sawBreak) join = true;
|
|
593
|
-
else if (sawPlaceholder) join = spaced && !
|
|
669
|
+
else if (sawPlaceholder) join = spaced && !bindsToPrevious(t, baseLang);
|
|
594
670
|
else join = spaced;
|
|
595
671
|
}
|
|
596
672
|
if (join) plainB += " ";
|
|
@@ -602,9 +678,11 @@ export class Converter {
|
|
|
602
678
|
} else if (seg.kind === "break") {
|
|
603
679
|
sawBreak = true;
|
|
604
680
|
} else if (seg.kind === "placeholder") {
|
|
681
|
+
plainB += DROPPED;
|
|
605
682
|
sawPlaceholder = true;
|
|
606
683
|
}
|
|
607
684
|
}
|
|
685
|
+
plainB = removeDropped(plainB, baseLang);
|
|
608
686
|
|
|
609
687
|
// Plain text is only worth keeping alongside SSML when it diverges from
|
|
610
688
|
// what stripping tags from the SSML would produce — i.e. when a
|
|
@@ -623,26 +701,24 @@ export class Converter {
|
|
|
623
701
|
let sb = "";
|
|
624
702
|
for (const seg of segments) {
|
|
625
703
|
if (seg.kind === "text") {
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
704
|
+
const { tag, attrs, lang } = seg.ctx!;
|
|
705
|
+
// A `sub` replaces all of its text, so spaces at its edges stay outside it to keep separating words.
|
|
706
|
+
const edges = tag === "sub" ? /^( *)([^]*?)( *)$/.exec(seg.text!)! : null;
|
|
707
|
+
const segText = edges ? edges[2] : seg.text!;
|
|
708
|
+
// A `sub` around only whitespace would speak its expansion a second time.
|
|
709
|
+
if (edges && segText === "") {
|
|
710
|
+
sb += seg.text!;
|
|
711
|
+
continue;
|
|
633
712
|
}
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
}
|
|
639
|
-
if (shiftsLanguage(seg.ctx!.lang)) {
|
|
640
|
-
sb += ` xml:lang="${ssmlAttrEscape(seg.ctx!.lang)}"`;
|
|
641
|
-
}
|
|
642
|
-
sb += `>${ssmlTextEscape(seg.text!)}</${tag}>`;
|
|
713
|
+
sb += edges?.[1] ?? "";
|
|
714
|
+
if (shiftsLanguage(lang)) {
|
|
715
|
+
// A language shift replaces the element's own tag, except `sub`, which can't carry xml:lang.
|
|
716
|
+
const inner = tag === "sub" ? ssmlElement(tag, attrs, segText) : ssmlTextEscape(segText);
|
|
717
|
+
sb += `<lang xml:lang="${ssmlAttrEscape(lang)}">${inner}</lang>`;
|
|
643
718
|
} else {
|
|
644
|
-
sb += ssmlTextEscape(
|
|
719
|
+
sb += tag ? ssmlElement(tag, attrs, segText) : ssmlTextEscape(segText);
|
|
645
720
|
}
|
|
721
|
+
sb += edges?.[3] ?? "";
|
|
646
722
|
} else if (seg.kind === "break") {
|
|
647
723
|
sb += "<break/>";
|
|
648
724
|
} else if (seg.kind === "placeholder") {
|
|
@@ -665,6 +741,17 @@ export class Converter {
|
|
|
665
741
|
}
|
|
666
742
|
}
|
|
667
743
|
|
|
744
|
+
// An abbreviation's expansion, "" when it has none.
|
|
745
|
+
function abbreviationExpansion(el: Element): string {
|
|
746
|
+
if (!extractNodeRoles(el).includes("abbreviation")) return "";
|
|
747
|
+
return normalizeWhitespace(el.getAttribute("title") ?? "", true).trim();
|
|
748
|
+
}
|
|
749
|
+
|
|
750
|
+
function ssmlElement(tag: string, attrs: Record<string, string> | undefined, text: string): string {
|
|
751
|
+
const attrString = Object.entries(attrs ?? {}).map(([k, v]) => ` ${k}="${ssmlAttrEscape(v)}"`).join("");
|
|
752
|
+
return `<${tag}${attrString}>${ssmlTextEscape(text)}</${tag}>`;
|
|
753
|
+
}
|
|
754
|
+
|
|
668
755
|
// A DOM <body> only counts as real content when the input actually wrote
|
|
669
756
|
// one — text/html parsing synthesizes a <body> around any fragment
|
|
670
757
|
// regardless of what was passed in, and that synthesized wrapper was
|