diff options
author | Scott Ullrich <sullrich@pfsense.org> | 2005-07-02 05:13:16 +0000 |
---|---|---|
committer | Scott Ullrich <sullrich@pfsense.org> | 2005-07-02 05:13:16 +0000 |
commit | 2e8eada098c43e53c79a2aa9a4627267006b9a26 (patch) | |
tree | 00b22ccf1f884bdbbeaaf8ab9e9e912afde5007f /usr/local/www/code-syntax-highlighter/shBrushXml.js | |
parent | 540b0ca74bc19669c7e03c65c1e62a5795c9b232 (diff) | |
download | pfsense-2e8eada098c43e53c79a2aa9a4627267006b9a26.zip pfsense-2e8eada098c43e53c79a2aa9a4627267006b9a26.tar.gz |
Add source code highlighting support
Diffstat (limited to 'usr/local/www/code-syntax-highlighter/shBrushXml.js')
-rw-r--r-- | usr/local/www/code-syntax-highlighter/shBrushXml.js | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/usr/local/www/code-syntax-highlighter/shBrushXml.js b/usr/local/www/code-syntax-highlighter/shBrushXml.js new file mode 100644 index 0000000..0286082 --- /dev/null +++ b/usr/local/www/code-syntax-highlighter/shBrushXml.js @@ -0,0 +1,61 @@ +dp.sh.Brushes.Xml = function() +{ + this.CssClass = 'dp-xml'; +} + +dp.sh.Brushes.Xml.prototype = new dp.sh.Highlighter(); +dp.sh.Brushes.Xml.Aliases = ['xml', 'xhtml', 'xslt', 'html', 'xhtml']; + +dp.sh.Brushes.Xml.prototype.ProcessRegexList = function() +{ + function push(array, value) + { + array[array.length] = value; + } + + /* If only there was a way to get index of a group within a match, the whole XML + could be matched with the expression looking something like that: + + (<!\[CDATA\[\s*.*\s*\]\]>) + | (<!--\s*.*\s*?-->) + | (<)*(\w+)*\s*(\w+)\s*=\s*(".*?"|'.*?'|\w+)(/*>)* + | (</?)(.*?)(/?>) + */ + var index = 0; + var match = null; + var regex = null; + + // Match CDATA in the following format <![ ... [ ... ]]> + // <\!\[[\w\s]*?\[(.|\s)*?\]\]> + this.GetMatches(new RegExp('<\\!\\[[\\w\\s]*?\\[(.|\\s)*?\\]\\]>', 'gm'), 'cdata'); + + // Match comments + // <!--\s*.*\s*?--> + this.GetMatches(new RegExp('<!--\\s*.*\\s*?-->', 'gm'), 'comments'); + + // Match attributes and their values + // (\w+)\s*=\s*(".*?"|\'.*?\'|\w+)* + regex = new RegExp('([\\w-\.]+)\\s*=\\s*(".*?"|\'.*?\'|\\w+)*', 'gm'); + while((match = regex.exec(this.code)) != null) + { + push(this.matches, new dp.sh.Match(match[1], match.index, 'attribute')); + + // if xml is invalid and attribute has no property value, ignore it + if(match[2] != undefined) + { + push(this.matches, new dp.sh.Match(match[2], match.index + match[0].indexOf(match[2]), 'attribute-value')); + } + } + + // Match opening and closing tag brackets + // </*\?*(?!\!)|/*\?*> + this.GetMatches(new RegExp('</*\\?*(?!\\!)|/*\\?*>', 'gm'), 'tag'); + + // Match tag names + // </*\?*\s*(\w+) + regex = new RegExp('</*\\?*\\s*([\\w-\.]+)', 'gm'); + while((match = regex.exec(this.code)) != null) + { + push(this.matches, new dp.sh.Match(match[1], match.index + match[0].indexOf(match[1]), 'tag-name')); + } +} |