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