-
Notifications
You must be signed in to change notification settings - Fork 26
Expand file tree
/
Copy pathhtml.js
More file actions
87 lines (84 loc) · 1.71 KB
/
Copy pathhtml.js
File metadata and controls
87 lines (84 loc) · 1.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
/**
* @name HTML
* @support inline style and event handlers
*/
import xml, { properties, xmlElement } from './xml.js';
let
/**
* An attribute, given by a regex source, whose value is written in another language
* @type {(name: string, sub: string) => import('../index.js').ShjRule}
*/
attribute = (name, sub) => ({
type: 'str',
// the name is left to the attribute rule of xml, only its value differs
match: RegExp(`(?<=\\s${name}\\s*)=\\s*('[^']*'|"[^"]*")`, 'gi'),
sub: [
{
type: 'oper',
match: /^=/g
},
{
// the quotes are left to the rule's own type
match: /(?<=['"])[^]+(?=['"]$)/g,
sub
}
]
}),
htmlElement = {
...xmlElement,
sub: [
attribute('style', 'css'),
attribute('on\\w+', 'js'),
...xmlElement.sub
]
};
export default /** @satisfies {import('../index.js').ShjGrammar} */ ([
{
type: 'class',
match: /<!DOCTYPE("[^"]*"|'[^']*'|[^"'>])*>/gi,
sub: [
{
type: 'str',
match: /"[^"]*"|'[^']*'/g
},
{
type: 'oper',
match: /^<!|>$/g
},
{
type: 'var',
match: /DOCTYPE/gi
}
]
},
{
match: RegExp(`<style${properties}>[^]*?</style\\s*>`, 'g'),
sub: [
{
match: RegExp(`^<style${properties}>`, 'g'),
sub: htmlElement.sub
},
{
match: /[^]*(?=<\/style\s*>$)/g,
sub: 'css'
},
htmlElement
]
},
{
match: RegExp(`<script${properties}>[^]*?</script\\s*>`, 'g'),
sub: [
{
match: RegExp(`^<script${properties}>`, 'g'),
sub: htmlElement.sub
},
{
match: /[^]*(?=<\/script\s*>$)/g,
sub: 'js'
},
htmlElement
]
},
// the element rule is the only one html extends, the rest of xml is reused as is
...xml.map(rule => rule === xmlElement ? htmlElement : rule)
]);