-
Notifications
You must be signed in to change notification settings - Fork 26
Expand file tree
/
Copy pathxml.js
More file actions
82 lines (80 loc) · 1.62 KB
/
Copy pathxml.js
File metadata and controls
82 lines (80 loc) · 1.62 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
/**
* @name XML
*/
let
nameStartChar = ":A-Z_a-z\u{C0}-\u{D6}\u{D8}-\u{F6}\u{F8}-\u{2FF}\u{370}-\u{37D}\u{37F}-\u{1FFF}\u{200C}-\u{200D}\u{2070}-\u{218F}\u{2C00}-\u{2FEF}\u{3001}-\u{D7FF}\u{F900}-\u{FDCF}\u{FDF0}-\u{FFFD}",
nameChar = nameStartChar + "\\-\\.0-9\u{B7}\u{0300}-\u{036F}\u{203F}-\u{2040}";
export let
name = `[${nameStartChar}][${nameChar}]*`,
properties = `(\\s+${name}\\s*(=\\s*([^"'>\\s][^>\\s]*|("|')(\\\\[^]|(?!\\4)[^])*\\4?)?)?)*\\s*`,
/** @type {{ match: RegExp, sub: import('../index.js').ShjGrammar }} */
xmlElement = {
match: RegExp(`<[\/!?]?${name}${properties}[\/!?]?>`, 'g'),
sub: [
{
type: 'var',
match: RegExp(`^<[\/!?]?${name}`, 'g'),
sub: [
{
type: 'oper',
match: /^<[\/!?]?/g
}
]
},
{
type: 'str',
match: /=\s*([^"'>\s][^>\s]*|("|')(\\[^]|(?!\2)[^])*\2?)/g,
sub: [
{
type: 'oper',
match: /^=/g
}
]
},
{
type: 'oper',
match: /[\/!?]?>/g
},
{
type: 'class',
match: RegExp(name, 'g')
}
]
};
export default /** @satisfies {import('../index.js').ShjGrammar} */ ([
{
match: /<!--[^]*?-->/g,
type: 'cmnt',
sub: 'todo'
},
{
type: 'class',
match: /<!\[CDATA\[[\s\S]*?\]\]>/gi
},
xmlElement,
// https://github.com/speed-highlight/core/issues/49
{
type: 'str',
match: RegExp(`<\\?${name}([^?]|\\?[^?>])*\\?+>`, 'g'),
sub: [
{
type: 'var',
match: RegExp(`^<\\?${name}`, 'g'),
sub: [
{
type: 'oper',
match: /^<\?/g
}
]
},
{
type: 'oper',
match: /\?+>$/g
}
]
},
{
type: 'var',
match: /&(#x?)?[\da-z]{1,8};/gi
}
]);