syntax highlighter的objective-c刷子

“Wordpress”中没有更早的文章了

“Wordpress”中没有上一篇文章了

这个刷子适用于很多类似的插件

2011-08-14更新

  1. 加入函数调用支持,
  2. 数字尾符
  3. 合成器方法中的内建关键词
/**
* Objective-c Brush For SyntaxHighlighter
*
* @version
* 1.3.0
*
* @copyright
* Copyright (C) 2011 www.dreamingwish.com
*
*/
;(function()
{
    // CommonJS
    typeof(require) != 'undefined' ? SyntaxHighlighter = require('shCore').SyntaxHighlighter : null;

    function Brush()
    {
        var datatypes = 'char bool BOOL double float int long short id void ';

        var keywords = 'IBAction IBOutlet SEL YES NO readwrite readonly nonatomic '         +
                        'retain assign readonly getter setter nil NULL '                    +
                        'super self copy '                                                  +
                        'break case catch class const copy __finally __exception __try '    +
                        'const_cast continue private public protected __declspec '          +
                        'default delete deprecated dllexport dllimport do dynamic_cast '    +
                        'else enum explicit extern if for friend goto inline '              +
                        'mutable naked namespace new noinline noreturn nothrow '            +
                        'register reinterpret_cast return selectany '                       +
                        'sizeof static static_cast struct switch template this '            +
                        'thread throw true false try typedef typeid typename union '        +
                        'using uuid virtual volatile whcar_t while '

        //顺序很重要
        this.regexList = [
                        { regex: SyntaxHighlighter.regexLib.singleLineCComments,        css: 'comments' },              // one line comments
                        { regex: SyntaxHighlighter.regexLib.multiLineCComments,         css: 'comments' },              // multiline comments
                        { regex: SyntaxHighlighter.regexLib.doubleQuotedString,         css: 'color3' },                // double quoted strings
                        { regex: SyntaxHighlighter.regexLib.singleQuotedString,         css: 'color3' },                // single quoted strings
                        { regex: new RegExp('@\\w+\\b', 'g'),                           css: 'color2' },                // keyword pink 以@开头的可能是关键字
                        { regex: new RegExp('@', 'g'),                                  css: 'color3' },                // nsstring @"fsafds" red 以@开头的可能是nsstring
                        { regex: new RegExp('\.?\\b\\d+[a-z]?\\b', 'g'),                css: 'color6' },                // number blue 数字可以这样 23 23.4 23.4f 3l
                        { regex: new RegExp('^ *#.*', 'gm'),                            css: 'color5' },                // preprocessor brown
                        { regex: new RegExp('\\b(NS[A-Z]|UI[A-Z]|CG[A-Z])\\w+\\b', 'g'),css: 'color4' },                // builtInType purple
                        { regex: new RegExp(this.getKeywords(datatypes), 'gm'),		    css: 'color2' },		        // datatypes pink
                        { regex: new RegExp(this.getKeywords(keywords), 'gm'),          css: 'color2' },                // keyword pink
                        { regex: new RegExp('\\s+\\w+\\b\\s*(?=(:|\\]))', 'g'),         css: 'color7' },                // function call dark green 函数调用可能和三元操作符冲突
                        ];
    };

    Brush.prototype	= new SyntaxHighlighter.Highlighter();
    Brush.aliases	= ['objc', 'obj-c', 'objective-c'];

    SyntaxHighlighter.brushes.Objc = Brush;
    // CommonJS
    typeof(exports) != 'undefined' ? exports.Brush = Brush : null;
})();

在插件目录的syntax highlighter .php文件(或类似文件的刷子数组里,添加一行:

'objc objective-c obj-c @shBrushObjc.js',

在插件目录的css目录里面修改css文件,如果使用的是默认主题 就修改这个文件:shThemeDefault.css
在这个文件里加上这些行,以支持其他几种颜色

/*shrimp purple*/
.syntaxhighlighter .color4, .syntaxhighlighter .color4 a {
  color: #663399 !important;
}
/*shrimp brown*/
.syntaxhighlighter .color5, .syntaxhighlighter .color5 a {
  color: #993300 !important;
}
/*shrimp blue*/
.syntaxhighlighter .color6, .syntaxhighlighter .color6 a {
  color: blue !important;
}
/*shrimp dark green*/
.syntaxhighlighter .color7, .syntaxhighlighter .color7 a {
  color: #005500 !important;
}

 

评论模块尚未加载