Skip to content

Commit

Permalink
Remove support for non-HTML doctypes
Browse files Browse the repository at this point in the history
Related to hast@2.4.0
  • Loading branch information
wooorm committed May 10, 2021
1 parent 868517c commit b8b104c
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 65 deletions.
32 changes: 1 addition & 31 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ var hast = zwitch('type', {
handlers: {
root: wrap(assertRoot),
element: wrap(assertElement),
doctype: wrap(assertDoctype),
doctype: _void,
comment: literal,
text: literal
}
Expand Down Expand Up @@ -130,33 +130,3 @@ function assertElement(node) {
'`element.tagName` should not be empty'
)
}

/**
* @param {unknown} node
* @returns {asserts node is Doctype}
*/
function assertDoctype(node) {
_void(node)

nodeAssert.strictEqual(
typeof node.name,
'string',
'`doctype` should have a `name`'
)

if (node.public !== null && node.public !== undefined) {
nodeAssert.strictEqual(
typeof node.public,
'string',
'`doctype.public` should be `string`'
)
}

if (node.system !== null && node.system !== undefined) {
nodeAssert.strictEqual(
typeof node.system,
'string',
'`doctype.system` should be `string`'
)
}
}
36 changes: 2 additions & 34 deletions test/doctype.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,41 +2,9 @@ import test from 'tape'
import {assert} from '../index.js'

test('assert(doctype)', function (t) {
t.throws(
function () {
assert({type: 'doctype'})
},
/`doctype` should have a `name`: `{ type: 'doctype' }`$/,
'should throw if a `doctype` doesn’t have a name'
)

t.doesNotThrow(function () {
assert({type: 'doctype', name: 'html'})
}, 'should allow names')

t.doesNotThrow(function () {
assert({type: 'doctype', name: ''})
}, 'should allow empty names')

t.throws(
function () {
assert({type: 'doctype', name: 'html', public: true})
},
/`doctype.public` should be `string`: `{ type: 'doctype', name: 'html', public: true }`$/,
'should throw if a `public` isn’t string'
)

t.throws(
function () {
assert({type: 'doctype', name: 'html', system: false})
},
/`doctype.system` should be `string`: `{ type: 'doctype', name: 'html', system: false }`$/,
'should throw if a `system` isn’t string'
)

t.doesNotThrow(function () {
assert({type: 'doctype', name: 'html', public: 'a', system: 'b'})
}, 'should allow string `public` and `system`')
assert({type: 'doctype'})
}, 'should allow doctypes')

t.end()
})

0 comments on commit b8b104c

Please sign in to comment.