/scripts/shBrushCSharp.js

http://github.com/alexgorbatchev/SyntaxHighlighter · JavaScript · 49 lines · 44 code · 4 blank · 1 comment · 7 complexity · 9364cc4b4e3bade4fbe91e8a3339e286 MD5 · raw file

  1. ;(function()
  2. {
  3. // CommonJS
  4. SyntaxHighlighter = SyntaxHighlighter || (typeof require !== 'undefined'? require('shCore').SyntaxHighlighter : null);
  5. function Brush()
  6. {
  7. var keywords = 'abstract as base bool break byte case catch char checked class const ' +
  8. 'continue decimal default delegate do double else enum event explicit volatile ' +
  9. 'extern false finally fixed float for foreach get goto if implicit in int ' +
  10. 'interface internal is lock long namespace new null object operator out ' +
  11. 'override params private protected public readonly ref return sbyte sealed set ' +
  12. 'short sizeof stackalloc static string struct switch this throw true try ' +
  13. 'typeof uint ulong unchecked unsafe ushort using virtual void while var ' +
  14. 'from group by into select let where orderby join on equals ascending descending';
  15. function fixComments(match, regexInfo)
  16. {
  17. var css = (match[0].indexOf("///") == 0)
  18. ? 'color1'
  19. : 'comments'
  20. ;
  21. return [new SyntaxHighlighter.Match(match[0], match.index, css)];
  22. }
  23. this.regexList = [
  24. { regex: SyntaxHighlighter.regexLib.singleLineCComments, func : fixComments }, // one line comments
  25. { regex: SyntaxHighlighter.regexLib.multiLineCComments, css: 'comments' }, // multiline comments
  26. { regex: /@"(?:[^"]|"")*"/g, css: 'string' }, // @-quoted strings
  27. { regex: SyntaxHighlighter.regexLib.doubleQuotedString, css: 'string' }, // strings
  28. { regex: SyntaxHighlighter.regexLib.singleQuotedString, css: 'string' }, // strings
  29. { regex: /^\s*#.*/gm, css: 'preprocessor' }, // preprocessor tags like #region and #endregion
  30. { regex: new RegExp(this.getKeywords(keywords), 'gm'), css: 'keyword' }, // c# keyword
  31. { regex: /\bpartial(?=\s+(?:class|interface|struct)\b)/g, css: 'keyword' }, // contextual keyword: 'partial'
  32. { regex: /\byield(?=\s+(?:return|break)\b)/g, css: 'keyword' } // contextual keyword: 'yield'
  33. ];
  34. this.forHtmlScript(SyntaxHighlighter.regexLib.aspScriptTags);
  35. };
  36. Brush.prototype = new SyntaxHighlighter.Highlighter();
  37. Brush.aliases = ['c#', 'c-sharp', 'csharp'];
  38. SyntaxHighlighter.brushes.CSharp = Brush;
  39. // CommonJS
  40. typeof(exports) != 'undefined' ? exports.Brush = Brush : null;
  41. })();