shBrushXml.js 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. ;(function()
  2. {
  3. // CommonJS
  4. SyntaxHighlighter = SyntaxHighlighter || (typeof require !== 'undefined'? require('shCore').SyntaxHighlighter : null);
  5. function Brush()
  6. {
  7. function process(match, regexInfo)
  8. {
  9. var constructor = SyntaxHighlighter.Match,
  10. code = match[0],
  11. tag = new XRegExp('(&lt;|<)[\\s\\/\\?]*(?<name>[:\\w-\\.]+)', 'xg').exec(code),
  12. result = []
  13. ;
  14. if (match.attributes != null)
  15. {
  16. var attributes,
  17. regex = new XRegExp('(?<name> [\\w:\\-\\.]+)' +
  18. '\\s*=\\s*' +
  19. '(?<value> ".*?"|\'.*?\'|\\w+)',
  20. 'xg');
  21. while ((attributes = regex.exec(code)) != null)
  22. {
  23. result.push(new constructor(attributes.name, match.index + attributes.index, 'color1'));
  24. result.push(new constructor(attributes.value, match.index + attributes.index + attributes[0].indexOf(attributes.value), 'string'));
  25. }
  26. }
  27. if (tag != null)
  28. result.push(
  29. new constructor(tag.name, match.index + tag[0].indexOf(tag.name), 'keyword')
  30. );
  31. return result;
  32. }
  33. this.regexList = [
  34. { regex: new XRegExp('(\\&lt;|<)\\!\\[[\\w\\s]*?\\[(.|\\s)*?\\]\\](\\&gt;|>)', 'gm'), css: 'color2' }, // <![ ... [ ... ]]>
  35. { regex: SyntaxHighlighter.regexLib.xmlComments, css: 'comments' }, // <!-- ... -->
  36. { regex: new XRegExp('(&lt;|<)[\\s\\/\\?]*(\\w+)(?<attributes>.*?)[\\s\\/\\?]*(&gt;|>)', 'sg'), func: process }
  37. ];
  38. };
  39. Brush.prototype = new SyntaxHighlighter.Highlighter();
  40. Brush.aliases = ['xml', 'xhtml', 'xslt', 'html'];
  41. SyntaxHighlighter.brushes.Xml = Brush;
  42. // CommonJS
  43. typeof(exports) != 'undefined' ? exports.Brush = Brush : null;
  44. })();