issue111, first try of auto completion for tag search box
[phpfspot.git] / autocomplete / js / shBrushXml.js
1 dp.sh.Brushes.Xml = function()\r
2 {\r
3         this.CssClass = 'dp-xml';\r
4 }\r
5 \r
6 dp.sh.Brushes.Xml.prototype     = new dp.sh.Highlighter();\r
7 dp.sh.Brushes.Xml.Aliases       = ['xml', 'xhtml', 'xslt', 'html', 'xhtml'];\r
8 \r
9 dp.sh.Brushes.Xml.prototype.ProcessRegexList = function()\r
10 {\r
11         function push(array, value)\r
12         {\r
13                 array[array.length] = value;\r
14         }\r
15         \r
16         /* If only there was a way to get index of a group within a match, the whole XML\r
17            could be matched with the expression looking something like that:\r
18         \r
19            (<!\[CDATA\[\s*.*\s*\]\]>)\r
20            | (<!--\s*.*\s*?-->)\r
21            | (<)*(\w+)*\s*(\w+)\s*=\s*(".*?"|'.*?'|\w+)(/*>)*\r
22            | (</?)(.*?)(/?>)\r
23         */\r
24         var index       = 0;\r
25         var match       = null;\r
26         var regex       = null;\r
27 \r
28         // Match CDATA in the following format <![ ... [ ... ]]>\r
29         // <\!\[[\w\s]*?\[(.|\s)*?\]\]>\r
30         this.GetMatches(new RegExp('<\\!\\[[\\w\\s]*?\\[(.|\\s)*?\\]\\]>', 'gm'), 'cdata');\r
31         \r
32         // Match comments\r
33         // <!--\s*.*\s*?-->\r
34         this.GetMatches(new RegExp('<!--\\s*.*\\s*?-->', 'gm'), 'comments');\r
35 \r
36         // Match attributes and their values\r
37         // (\w+)\s*=\s*(".*?"|\'.*?\'|\w+)*\r
38         regex = new RegExp('([\\w-\.]+)\\s*=\\s*(".*?"|\'.*?\'|\\w+)*', 'gm');\r
39         while((match = regex.exec(this.code)) != null)\r
40         {\r
41                 push(this.matches, new dp.sh.Match(match[1], match.index, 'attribute'));\r
42         \r
43                 // if xml is invalid and attribute has no property value, ignore it     \r
44                 if(match[2] != undefined)\r
45                 {\r
46                         push(this.matches, new dp.sh.Match(match[2], match.index + match[0].indexOf(match[2]), 'attribute-value'));\r
47                 }\r
48         }\r
49 \r
50         // Match opening and closing tag brackets\r
51         // </*\?*(?!\!)|/*\?*>\r
52         this.GetMatches(new RegExp('</*\\?*(?!\\!)|/*\\?*>', 'gm'), 'tag');\r
53 \r
54         // Match tag names\r
55         // </*\?*\s*(\w+)\r
56         regex = new RegExp('</*\\?*\\s*([\\w-\.]+)', 'gm');\r
57         while((match = regex.exec(this.code)) != null)\r
58         {\r
59                 push(this.matches, new dp.sh.Match(match[1], match.index + match[0].indexOf(match[1]), 'tag-name'));\r
60         }\r
61 }\r