git ssb

1+

Matt McKegg / mutant



Tree: 994654fc520c8585e99de99665ac7140ce87a446

Files: 994654fc520c8585e99de99665ac7140ce87a446 / lib / parse-tag.js

1049 bytesRaw
1// FROM: https://raw.githubusercontent.com/Matt-Esch/virtual-dom/master/virtual-hyperscript/parse-tag.js
2
3'use strict'
4
5var split = require('browser-split')
6
7var classIdSplit = /([\.#]?[a-zA-Z0-9\u007F-\uFFFF_:-]+)/
8var notClassId = /^\.|#/
9
10module.exports = parseTag
11
12function parseTag (tag, attributes, namespace) {
13 if (!tag) {
14 return 'DIV'
15 }
16
17 var noId = !(attributes.hasOwnProperty('id'))
18
19 var tagParts = split(tag, classIdSplit)
20 var tagName = null
21
22 if (notClassId.test(tagParts[1])) {
23 tagName = 'DIV'
24 }
25
26 var classes, part, type, i, id
27
28 for (i = 0; i < tagParts.length; i++) {
29 part = tagParts[i]
30
31 if (!part) {
32 continue
33 }
34
35 type = part.charAt(0)
36
37 if (!tagName) {
38 tagName = part
39 } else if (type === '.') {
40 classes = classes || []
41 classes.push(part.substring(1, part.length))
42 } else if (type === '#' && noId) {
43 id = part.substring(1, part.length)
44 }
45 }
46
47 return {
48 tagName: namespace ? tagName : tagName.toUpperCase(),
49 classes: classes,
50 id: id
51 }
52}
53

Built with git-ssb-web