Skip to content

Commit e294d41

Browse files
committed
Remove support for non-HTML doctypes
Related to syntax-tree/[email protected].
1 parent 7882a8c commit e294d41

File tree

2 files changed

+10
-121
lines changed

2 files changed

+10
-121
lines changed

Diff for: lib/doctype.js

+5-37
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,8 @@
1-
import {ccount} from 'ccount'
2-
import {stringifyEntities} from 'stringify-entities'
3-
4-
export function doctype(ctx, node) {
5-
var sep = ctx.tightDoctype ? '' : ' '
6-
var parts = ['<!' + (ctx.upperDoctype ? 'DOCTYPE' : 'doctype')]
7-
8-
if (node.name) {
9-
parts.push(sep, node.name)
10-
11-
if (node.public !== undefined && node.public !== null) {
12-
parts.push(' public', sep, quote(ctx, node.public))
13-
} else if (node.system !== undefined && node.system !== null) {
14-
parts.push(' system')
15-
}
16-
17-
if (node.system !== undefined && node.system !== null) {
18-
parts.push(sep, quote(ctx, node.system))
19-
}
20-
}
21-
22-
return parts.join('') + '>'
23-
}
24-
25-
function quote(ctx, value) {
26-
var string = String(value)
27-
var quote =
28-
ccount(string, ctx.quote) > ccount(string, ctx.alternative)
29-
? ctx.alternative
30-
: ctx.quote
31-
1+
export function doctype(ctx) {
322
return (
33-
quote +
34-
stringifyEntities(
35-
string,
36-
Object.assign({}, ctx.entities, {subset: ['<', '&', quote]})
37-
) +
38-
quote
3+
'<!' +
4+
(ctx.upperDoctype ? 'DOCTYPE' : 'doctype') +
5+
(ctx.tightDoctype ? '' : ' ') +
6+
'html>'
397
)
408
}

Diff for: test/doctype.js

+5-84
Original file line numberDiff line numberDiff line change
@@ -2,103 +2,24 @@ import test from 'tape'
22
import {u} from 'unist-builder'
33
import {toHtml} from '../index.js'
44

5-
test('`text`', function (t) {
5+
test('`doctype`', function (t) {
66
t.deepEqual(
77
toHtml(u('doctype')),
8-
'<!doctype>',
9-
'should serialize doctypes without `name`'
10-
)
11-
12-
t.deepEqual(
13-
toHtml(u('doctype', {name: 'html'})),
148
'<!doctype html>',
15-
'should serialize doctypes with `name`'
9+
'should serialize doctypes'
1610
)
1711

1812
t.deepEqual(
19-
toHtml(u('doctype', {name: 'html'}), {tightDoctype: true}),
13+
toHtml(u('doctype'), {tightDoctype: true}),
2014
'<!doctypehtml>',
21-
'should serialize doctypes with `name` tightly in `tightDoctype` mode'
15+
'should serialize doctypes tightly in `tightDoctype` mode'
2216
)
2317

2418
t.deepEqual(
25-
toHtml(u('doctype', {name: 'html'}), {upperDoctype: true}),
19+
toHtml(u('doctype'), {upperDoctype: true}),
2620
'<!DOCTYPE html>',
2721
'should serialize uppercase doctypes in `upperDoctype` mode'
2822
)
2923

30-
t.deepEqual(
31-
toHtml(
32-
u('doctype', {
33-
name: 'html',
34-
public: '-//W3C//DTD XHTML 1.0 Transitional//EN'
35-
})
36-
),
37-
'<!doctype html public "-//W3C//DTD XHTML 1.0 Transitional//EN">',
38-
'should serialize doctypes with a public identifier'
39-
)
40-
41-
t.deepEqual(
42-
toHtml(
43-
u('doctype', {
44-
name: 'html',
45-
public: '-//W3C//DTD XHTML 1.0 Transitional//EN'
46-
}),
47-
{tightDoctype: true}
48-
),
49-
'<!doctypehtml public"-//W3C//DTD XHTML 1.0 Transitional//EN">',
50-
'should serialize doctypes with a public identifier tightly in `tightDoctype` mode'
51-
)
52-
53-
t.deepEqual(
54-
toHtml(u('doctype', {name: 'html', system: 'about:legacy-compat'})),
55-
'<!doctype html system "about:legacy-compat">',
56-
'should serialize doctypes with a system identifier'
57-
)
58-
59-
t.deepEqual(
60-
toHtml(u('doctype', {name: 'html', system: 'about:legacy-compat'}), {
61-
tightDoctype: true
62-
}),
63-
'<!doctypehtml system"about:legacy-compat">',
64-
'should serialize doctypes with a system identifier tightly in `tightDoctype` mode'
65-
)
66-
67-
t.deepEqual(
68-
toHtml(
69-
u('doctype', {
70-
name: 'html',
71-
public: '-//W3C//DTD HTML 4.01//',
72-
system: 'http://www.w3.org/TR/html4/strict.dtd'
73-
})
74-
),
75-
'<!doctype html public "-//W3C//DTD HTML 4.01//" "http://www.w3.org/TR/html4/strict.dtd">',
76-
'should serialize doctypes with both identifiers'
77-
)
78-
79-
t.deepEqual(
80-
toHtml(
81-
u('doctype', {
82-
name: 'html',
83-
public: '-//W3C//DTD HTML 4.01//',
84-
system: 'http://www.w3.org/TR/html4/strict.dtd'
85-
}),
86-
{tightDoctype: true}
87-
),
88-
'<!doctypehtml public"-//W3C//DTD HTML 4.01//""http://www.w3.org/TR/html4/strict.dtd">',
89-
'should serialize doctypes with both identifiers tightly in `tightDoctype` mode'
90-
)
91-
92-
t.deepEqual(
93-
toHtml(
94-
u('doctype', {
95-
name: 'html',
96-
system: 'taco"'
97-
})
98-
),
99-
"<!doctype html system 'taco\"'>",
100-
'should quote smartly'
101-
)
102-
10324
t.end()
10425
})

0 commit comments

Comments
 (0)