Skip to content

Commit

Permalink
Update schema to reflect changes to GH
Browse files Browse the repository at this point in the history
*   `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
  • Loading branch information
wooorm committed Aug 3, 2023
1 parent ee834d3 commit ffee970
Show file tree
Hide file tree
Showing 9 changed files with 1,139 additions and 26 deletions.
1 change: 1 addition & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
coverage/
*.html
*.md
325 changes: 325 additions & 0 deletions input.html

Large diffs are not rendered by default.

69 changes: 48 additions & 21 deletions lib/schema.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// Couple of ARIA attributes allowed in several, but not all, places.
const aria = ['ariaDescribedBy', 'ariaLabel', 'ariaLabelledBy']

/**
* Default schema.
*
Expand All @@ -15,18 +18,53 @@ export const defaultSchema = {
tr: ['table']
},
attributes: {
a: ['href'],
a: [
...aria,
// Note: these 3 are used by GFM footnotes, they do work on all links.
'dataFootnoteBackref',
'dataFootnoteRef',
['className', 'data-footnote-backref'],
'href'
],
blockquote: ['cite'],
// Note: this class is not normally allowed by GH, when manually writing
// `code` as HTML in markdown, they adds it some other way.
// We can’t do that, so we have to allow it.
code: [['className', /^language-./]],
del: ['cite'],
div: ['itemScope', 'itemType'],
img: ['longDesc', 'src'],
dl: [...aria],
// Note: these 2 are used by GFM footnotes, they *sometimes* work.
h2: [
['id', 'footnote-label'],
['className', 'sr-only']
],
img: [...aria, 'longDesc', 'src'],
// Note: `input` is not normally allowed by GH, when manually writing
// it in markdown, they add it from tasklists some other way.
// We can’t do that, so we have to allow it.
input: [
['disabled', true],
['type', 'checkbox']
],
ins: ['cite'],
// Note: this class is not normally allowed by GH, when manually writing
// `li` as HTML in markdown, they adds it some other way.
// We can’t do that, so we have to allow it.
li: [['className', 'task-list-item']],
// Note: this class is not normally allowed by GH, when manually writing
// `ol` as HTML in markdown, they adds it some other way.
// We can’t do that, so we have to allow it.
ol: [...aria, ['className', 'contains-task-list']],
q: ['cite'],
section: ['dataFootnotes', ['className', 'footnotes']],
source: ['srcSet'],
summary: [...aria],
table: [...aria],
// Note: this class is not normally allowed by GH, when manually writing
// `ol` as HTML in markdown, they adds it some other way.
// We can’t do that, so we have to allow it.
ul: [...aria, ['className', 'contains-task-list']],
'*': [
'abbr',
'accept',
Expand All @@ -35,10 +73,6 @@ export const defaultSchema = {
'action',
'align',
'alt',
'ariaDescribedBy',
'ariaHidden',
'ariaLabel',
'ariaLabelledBy',
'axis',
'border',
'cellPadding',
Expand Down Expand Up @@ -94,16 +128,14 @@ export const defaultSchema = {
'tabIndex',
'target',
'title',
'type',
'useMap',
'vAlign',
'vSpace',
'value',
'width'
]
},
clobberPrefix: 'user-content-',
clobber: ['id', 'name'],
clobber: ['ariaDescribedBy', 'ariaLabelledBy', 'id', 'name'],
protocols: {
href: ['http', 'https', 'irc', 'ircs', 'mailto', 'xmpp'],
cite: ['http', 'https'],
Expand All @@ -116,24 +148,17 @@ export const defaultSchema = {
strip: ['script'],
tagNames: [
'a',
'abbr',
'b',
'bdo',
'blockquote',
'br',
'caption',
'cite',
'code',
'dd',
'del',
'details',
'dfn',
'div',
'dl',
'dt',
'em',
'figcaption',
'figure',
'h1',
'h2',
'h3',
Expand All @@ -143,21 +168,25 @@ export const defaultSchema = {
'hr',
'i',
'img',
// Note: `input` is not normally allowed by GH, when manually writing
// it in markdown, they add it from tasklists some other way.
// We can’t do that, so we have to allow it.
'input',
'ins',
'kbd',
'li',
'mark',
'ol',
'p',
'picture',
'pre',
'q',
'rp',
'rt',
'ruby',
's',
'samp',
'small',
'section',
'source',
'span',
'strike',
'strong',
Expand All @@ -170,11 +199,9 @@ export const defaultSchema = {
'tfoot',
'th',
'thead',
'time',
'tr',
'tt',
'ul',
'var',
'wbr'
'var'
]
}
9 changes: 7 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,23 +43,28 @@
"devDependencies": {
"@types/node": "^20.0.0",
"@types/ungap__structured-clone": "^0.3.0",
"aria-attributes": "^2.0.0",
"c8": "^8.0.0",
"deepmerge": "^4.0.0",
"hast-util-from-html": "^1.0.0",
"hast-util-to-html": "^8.0.0",
"hastscript": "^8.0.0",
"html-element-attributes": "^3.0.0",
"html-tag-names": "^2.0.0",
"prettier": "^3.0.0",
"remark-cli": "^11.0.0",
"remark-preset-wooorm": "^9.0.0",
"type-coverage": "^2.0.0",
"typescript": "^5.0.0",
"unist-builder": "^4.0.0",
"unist-util-visit": "^5.0.0",
"xo": "^0.55.0"
},
"scripts": {
"prepack": "npm run build && npm run format",
"build": "tsc --build --clean && tsc --build && type-coverage",
"format": "remark . -qfo && prettier . -w --log-level warn && xo --fix",
"test-api": "node --conditions development test.js",
"test-api": "node --conditions development test/index.js",
"test-coverage": "c8 --100 --reporter lcov npm run test-api",
"test": "npm run build && npm run format && npm run test-coverage"
},
Expand Down Expand Up @@ -90,7 +95,7 @@
"overrides": [
{
"files": [
"test.js"
"test/**/*.js"
],
"rules": {
"max-nested-callbacks": "off",
Expand Down
Loading

0 comments on commit ffee970

Please sign in to comment.