-
Notifications
You must be signed in to change notification settings - Fork 0
/
tag.js
50 lines (46 loc) · 1.42 KB
/
tag.js
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
// Source copied and then modified from
// https://github.com/remarkjs/remark/blob/master/packages/remark-parse/lib/util/html.js
//
// MIT License https://github.com/remarkjs/remark/blob/master/license
// https://github.com/DmitrySoshnikov/babel-plugin-transform-modern-regexp#dotall-s-flag
// Firefox and other browsers don't support the dotAll ("s") flag, but it can be polyfilled via this:
const dotAllPolyfill = '[\0-\uFFFF]'
const attributeName = '[a-zA-Z_:][a-zA-Z0-9:._-]*'
const unquoted = '[^"\'=<>`\\u0000-\\u0020]+'
const singleQuoted = "'[^']*'"
const doubleQuoted = '"[^"]*"'
const jsProps = '{.*}'.replace('.', dotAllPolyfill)
const attributeValue =
'(?:' +
unquoted +
'|' +
singleQuoted +
'|' +
doubleQuoted +
'|' +
jsProps +
')'
const attribute =
'(?:\\s+' + attributeName + '(?:\\s*=\\s*' + attributeValue + ')?)'
const openTag = '<[A-Za-z]*[A-Za-z0-9\\.\\-]*' + attribute + '*\\s*\\/?>'
const closeTag = '<\\/[A-Za-z][A-Za-z0-9\\.\\-]*\\s*>'
const comment = '<!---->|<!--(?:-?[^>-])(?:-?[^-])*-->'
const processing = '<[?].*?[?]>'.replace('.', dotAllPolyfill)
const declaration = '<![A-Za-z]+\\s+[^>]*>'
const cdata = '<!\\[CDATA\\[[\\s\\S]*?\\]\\]>'
exports.openCloseTag = new RegExp('^(?:' + openTag + '|' + closeTag + ')')
exports.tag = new RegExp(
'^(?:' +
openTag +
'|' +
closeTag +
'|' +
comment +
'|' +
processing +
'|' +
declaration +
'|' +
cdata +
')'
)