Skip to content

Commit ffee970

Browse files
committed
Update schema to reflect changes to GH
* `ariaHidden` is not supported by GH * ARIA attributes `ariaDescribedBy`, `ariaLabel`, and `ariaLabelledBy` are allowed on `a`, `dl`, `ol`, and `ul` by GH * Add support for footnotes and their properties * Add `language-*` classes on `code` * Add `contains-task-list` class on `ol`, `ul` * Remove `vSpace` * Remove `type`, other than on `input` * Add `ariaDescribedBy`, `ariaLabelledBy` to clobbered attributes * Remove `abbr`, `bdo`, `caption`, `cite`, `dfn`, `figcaption`, `figure`, `mark`, `small`, `time`, `wbr` elements * Add `picture`, `source` elements
1 parent ee834d3 commit ffee970

File tree

9 files changed

+1139
-26
lines changed

9 files changed

+1139
-26
lines changed

.prettierignore

+1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
coverage/
2+
*.html
23
*.md

input.html

+325
Large diffs are not rendered by default.

lib/schema.js

+48-21
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
// Couple of ARIA attributes allowed in several, but not all, places.
2+
const aria = ['ariaDescribedBy', 'ariaLabel', 'ariaLabelledBy']
3+
14
/**
25
* Default schema.
36
*
@@ -15,18 +18,53 @@ export const defaultSchema = {
1518
tr: ['table']
1619
},
1720
attributes: {
18-
a: ['href'],
21+
a: [
22+
...aria,
23+
// Note: these 3 are used by GFM footnotes, they do work on all links.
24+
'dataFootnoteBackref',
25+
'dataFootnoteRef',
26+
['className', 'data-footnote-backref'],
27+
'href'
28+
],
1929
blockquote: ['cite'],
30+
// Note: this class is not normally allowed by GH, when manually writing
31+
// `code` as HTML in markdown, they adds it some other way.
32+
// We can’t do that, so we have to allow it.
33+
code: [['className', /^language-./]],
2034
del: ['cite'],
2135
div: ['itemScope', 'itemType'],
22-
img: ['longDesc', 'src'],
36+
dl: [...aria],
37+
// Note: these 2 are used by GFM footnotes, they *sometimes* work.
38+
h2: [
39+
['id', 'footnote-label'],
40+
['className', 'sr-only']
41+
],
42+
img: [...aria, 'longDesc', 'src'],
43+
// Note: `input` is not normally allowed by GH, when manually writing
44+
// it in markdown, they add it from tasklists some other way.
45+
// We can’t do that, so we have to allow it.
2346
input: [
2447
['disabled', true],
2548
['type', 'checkbox']
2649
],
2750
ins: ['cite'],
51+
// Note: this class is not normally allowed by GH, when manually writing
52+
// `li` as HTML in markdown, they adds it some other way.
53+
// We can’t do that, so we have to allow it.
2854
li: [['className', 'task-list-item']],
55+
// Note: this class is not normally allowed by GH, when manually writing
56+
// `ol` as HTML in markdown, they adds it some other way.
57+
// We can’t do that, so we have to allow it.
58+
ol: [...aria, ['className', 'contains-task-list']],
2959
q: ['cite'],
60+
section: ['dataFootnotes', ['className', 'footnotes']],
61+
source: ['srcSet'],
62+
summary: [...aria],
63+
table: [...aria],
64+
// Note: this class is not normally allowed by GH, when manually writing
65+
// `ol` as HTML in markdown, they adds it some other way.
66+
// We can’t do that, so we have to allow it.
67+
ul: [...aria, ['className', 'contains-task-list']],
3068
'*': [
3169
'abbr',
3270
'accept',
@@ -35,10 +73,6 @@ export const defaultSchema = {
3573
'action',
3674
'align',
3775
'alt',
38-
'ariaDescribedBy',
39-
'ariaHidden',
40-
'ariaLabel',
41-
'ariaLabelledBy',
4276
'axis',
4377
'border',
4478
'cellPadding',
@@ -94,16 +128,14 @@ export const defaultSchema = {
94128
'tabIndex',
95129
'target',
96130
'title',
97-
'type',
98131
'useMap',
99132
'vAlign',
100-
'vSpace',
101133
'value',
102134
'width'
103135
]
104136
},
105137
clobberPrefix: 'user-content-',
106-
clobber: ['id', 'name'],
138+
clobber: ['ariaDescribedBy', 'ariaLabelledBy', 'id', 'name'],
107139
protocols: {
108140
href: ['http', 'https', 'irc', 'ircs', 'mailto', 'xmpp'],
109141
cite: ['http', 'https'],
@@ -116,24 +148,17 @@ export const defaultSchema = {
116148
strip: ['script'],
117149
tagNames: [
118150
'a',
119-
'abbr',
120151
'b',
121-
'bdo',
122152
'blockquote',
123153
'br',
124-
'caption',
125-
'cite',
126154
'code',
127155
'dd',
128156
'del',
129157
'details',
130-
'dfn',
131158
'div',
132159
'dl',
133160
'dt',
134161
'em',
135-
'figcaption',
136-
'figure',
137162
'h1',
138163
'h2',
139164
'h3',
@@ -143,21 +168,25 @@ export const defaultSchema = {
143168
'hr',
144169
'i',
145170
'img',
171+
// Note: `input` is not normally allowed by GH, when manually writing
172+
// it in markdown, they add it from tasklists some other way.
173+
// We can’t do that, so we have to allow it.
146174
'input',
147175
'ins',
148176
'kbd',
149177
'li',
150-
'mark',
151178
'ol',
152179
'p',
180+
'picture',
153181
'pre',
154182
'q',
155183
'rp',
156184
'rt',
157185
'ruby',
158186
's',
159187
'samp',
160-
'small',
188+
'section',
189+
'source',
161190
'span',
162191
'strike',
163192
'strong',
@@ -170,11 +199,9 @@ export const defaultSchema = {
170199
'tfoot',
171200
'th',
172201
'thead',
173-
'time',
174202
'tr',
175203
'tt',
176204
'ul',
177-
'var',
178-
'wbr'
205+
'var'
179206
]
180207
}

package.json

+7-2
Original file line numberDiff line numberDiff line change
@@ -43,23 +43,28 @@
4343
"devDependencies": {
4444
"@types/node": "^20.0.0",
4545
"@types/ungap__structured-clone": "^0.3.0",
46+
"aria-attributes": "^2.0.0",
4647
"c8": "^8.0.0",
4748
"deepmerge": "^4.0.0",
49+
"hast-util-from-html": "^1.0.0",
4850
"hast-util-to-html": "^8.0.0",
4951
"hastscript": "^8.0.0",
52+
"html-element-attributes": "^3.0.0",
53+
"html-tag-names": "^2.0.0",
5054
"prettier": "^3.0.0",
5155
"remark-cli": "^11.0.0",
5256
"remark-preset-wooorm": "^9.0.0",
5357
"type-coverage": "^2.0.0",
5458
"typescript": "^5.0.0",
5559
"unist-builder": "^4.0.0",
60+
"unist-util-visit": "^5.0.0",
5661
"xo": "^0.55.0"
5762
},
5863
"scripts": {
5964
"prepack": "npm run build && npm run format",
6065
"build": "tsc --build --clean && tsc --build && type-coverage",
6166
"format": "remark . -qfo && prettier . -w --log-level warn && xo --fix",
62-
"test-api": "node --conditions development test.js",
67+
"test-api": "node --conditions development test/index.js",
6368
"test-coverage": "c8 --100 --reporter lcov npm run test-api",
6469
"test": "npm run build && npm run format && npm run test-coverage"
6570
},
@@ -90,7 +95,7 @@
9095
"overrides": [
9196
{
9297
"files": [
93-
"test.js"
98+
"test/**/*.js"
9499
],
95100
"rules": {
96101
"max-nested-callbacks": "off",

0 commit comments

Comments
 (0)