{"id":80,"date":"2013-03-25T15:46:27","date_gmt":"2013-03-25T07:46:27","guid":{"rendered":"http:\/\/ynxp.net\/?p=80"},"modified":"2013-03-25T15:46:27","modified_gmt":"2013-03-25T07:46:27","slug":"%e8%87%aa%e5%ae%9a%e4%b9%89-wp-syntax-%e7%9a%84%e4%bb%a3%e7%a0%81%e6%a0%b7%e5%bc%8f","status":"publish","type":"post","link":"http:\/\/ynxp.net\/?p=80","title":{"rendered":"\u81ea\u5b9a\u4e49 WP-Syntax \u7684\u4ee3\u7801\u6837\u5f0f"},"content":{"rendered":"<p>\u5728Wordpress\u4e0b\uff0c<a href=\"http:\/\/wordpress.org\/extend\/plugins\/wp-syntax\/\">WP-Syntax<\/a>\u662f\u4e00\u6b3e\u975e\u5e38\u4f18\u79c0\u7684\u4ee3\u7801\u9ad8\u4eae\u663e\u793a\u63d2\u4ef6\uff0c\u5b83\u5c06\u5f00\u6e90\u7684\u4ee3\u7801\u9ad8\u4eae\u5de5\u5177<a href=\"http:\/\/qbnz.com\/highlighter\/\">GeSHi<\/a>\u5e94\u7528\u5230\u4e86Wordpress\u4e2d\u3002<\/p>\n<p>\u4f46WP-Syntax\u63d0\u4f9b\u7684\u9ed8\u8ba4\u6837\u5f0f\u5e76\u4e0d\u662f\u5bf9\u4e8e\u6240\u6709WordPress\u4e3b\u9898\u90fd\u9002\u7528\u7684\uff0c\u5c31\u50cf\u8fd9\u91cc\u73b0\u5728\u4f7f\u7528\u7684Unborn\u4e3b\u9898\uff0c\u90a3\u4e48\u5982\u4f55\u6839\u636e\u81ea\u5df1\u4f7f\u7528\u7684\u4e3b\u9898\u6765\u6253\u9020\u9002\u5408\u81ea\u5df1\u7684\u4ee3\u7801\u6837\u5f0f\u4ee5\u53ca\u914d\u8272\u65b9\u6848\u5462\uff1f\u672c\u6587\u5c06\u8fdb\u884c\u4e00\u4e0b\u7b80\u8981\u7684\u4ecb\u7ecd\u3002<\/p>\n<p><!--more--><\/p>\n<h4>\u57fa\u672c\u6837\u5f0f<\/h4>\n<p>WP-Syntax\u9ed8\u8ba4\u4f7f\u7528\u63d2\u4ef6\u5185\u7684<code>wp-syntax.css<\/code>\u4f5c\u4e3a\u5176\u57fa\u672c\u5e03\u5c40\u6837\u5f0f\u8868\u3002\u5728\u9700\u8981\u6839\u636e\u4e3b\u9898\u98ce\u683c\u8fdb\u884c\u6539\u9020\u7684\u65f6\u5019\uff0c\u53ea\u9700\u5c06\u9ed8\u8ba4\u7684<code>wp-content\/plugins\/wp-syntax\/wp-syntax.css<\/code>\u6587\u4ef6\u590d\u5236\u5230\u4e3b\u9898\u76ee\u5f55\u518d\u8fdb\u884c\u6539\u9020\u3002\u5f53\u7136\uff0c\u4f60\u4e5f\u53ef\u4ee5\u81ea\u5df1\u5728\u4e3b\u9898\u76ee\u5f55\u4e0b\u65b0\u5efa\u4e00\u4e2a<code>wp-syntax.css<\/code>\u6587\u4ef6\u7528\u4e8e\u8986\u76d6\u9ed8\u8ba4\u6837\u5f0f\u3002<\/p>\n<p><code>.wp_syntax<\/code>\u5143\u7d20\u7684<code>background-color<\/code>\u5b9a\u4e49\u4e86\u6574\u4e2a\u4ee3\u7801\u533a\u57df\u7684\u80cc\u666f\u8272\uff0c\u53ef\u4ee5\u4f7f\u7528<a href=\"http:\/\/www.colorpicker.com\/\">\u5728\u7ebf\u53d6\u8272\u5668<\/a>\u83b7\u53d6\u989c\u8272\u4ee3\u7801\u3002\u6709\u9700\u8981\u7684\u8bdd\u4e5f\u53ef\u4ee5\u5c06\u5176\u66ff\u6362\u6210\u80cc\u666f\u56fe\u7247\u3002<\/p>\n<p><code>.wp_syntax .line_numbers<\/code>\u5143\u7d20\u5185\u53ef\u4ee5\u5b9a\u4e49\u5de6\u4fa7\u53ef\u9009\u7684\u884c\u53f7\u533a\u57df\u7684\u6837\u5f0f\u3002<\/p>\n<h4>\u9ad8\u7ea7\u81ea\u5b9a\u4e49\u6837\u5f0f<\/h4>\n<p>\u56e0\u4e3a\u9ad8\u4eae\u663e\u793a\u91c7\u53d6\u7684\u662finline CSS\u7684\u65b9\u5f0f\uff0c\u800c\u4e14\u4e5f\u4e0d\u4f1a\u5bf9\u9ad8\u4eae\u663e\u793a\u7684\u90e8\u5206\u6dfb\u52a0class\uff0c\u6240\u4ee5\u6211\u4eec\u4e0d\u80fd\u4f7f\u7528\u5916\u90e8\u6837\u5f0f\u8868\u6765\u8986\u76d6\u4ee3\u7801\u6587\u5b57\u7684\u6837\u5f0f\u3002\u8fd9\u65f6\uff0c\u6211\u4eec\u9700\u8981\u5728function.php\u4e2d\u6dfb\u52a0\u5982\u4e0b\u7684\u4ee3\u7801\u6765\u81ea\u5b9a\u4e49\u4ee3\u7801\u6837\u5f0f\u7684\u8f93\u51fa\uff1a<\/p>\n<pre lang=\"php\" line=\"1\">add_action('wp_syntax_init_geshi', 'my_custom_geshi_styles');\n\nfunction my_custom_geshi_styles(&amp;$geshi)\n{\n    \/\/ We need some customizations here\n}<\/pre>\n<p>\u4e5f\u5c31\u662f\u5728WP-Syntax\u5728\u521d\u59cb\u5316GeSHi\u7684\u65f6\u5019\uff0c\u52a0\u5165\u6211\u4eec\u7684\u4ee3\u7801\uff0c\u4fee\u6539GeSHi\u9884\u5b9a\u4e49\u7684\u6837\u5f0f\u3002<\/p>\n<p>\u5728GeSHi\u7684<a href=\"http:\/\/qbnz.com\/highlighter\/geshi-doc.html\">\u5e2e\u52a9\u6587\u6863<\/a>\u4e2d\u53ef\u4ee5\u770b\u5230\uff0c\u53ef\u4ee5\u8bbe\u7f6e\u7684\u9879\u6709\uff1a<\/p>\n<ul>\n<li>Overall Styles &#8211; \u603b\u4f53\u6837\u5f0f<\/li>\n<li>Line Number Styles &#8211; \u884c\u53f7\u6837\u5f0f<\/li>\n<li>Keyword Styles &#8211; \u5173\u952e\u5b57\u6837\u5f0f<\/li>\n<li>Comment Styles &#8211; \u6ce8\u91ca\u6837\u5f0f<\/li>\n<li>Other Styles &#8211; \u5176\u4ed6<\/li>\n<\/ul>\n<p>Overall styles\u5c06\u5f71\u54cd\u6240\u6709\u4ee3\u7801\uff0c\u4f46\u4f1a\u88ab\u540e\u9762\u90a3\u4e9b\u6837\u5f0f\u8986\u76d6\u3002\u8bbe\u7f6e\u65b9\u6cd5\u90fd\u5dee\u4e0d\u591a\uff0c\u90fd\u662f\u8c03\u7528<code>$geshi-&gt;set_<em>[token_type]<\/em>_style<\/code>\u8fd9\u6837\u7684\u51fd\u6570\u6765\u5b8c\u6210\u3002\u5177\u4f53\u51fd\u6570\u7684\u7528\u6cd5\u8fd8\u662f\u8981\u53bb\u770b\u5e2e\u52a9\u6587\u6863\uff0c\u5176\u4e2d\u53c2\u6570\u53ef\u80fd\u4f1a\u6709<code>$group<\/code>, <code>$styles<\/code>, <code>$preserve_defaults<\/code>\u7b49\u3002<\/p>\n<p><code>$group<\/code>\u4ee3\u8868\u67d0\u79cd\u7c7b\u578btoken\u7684\u7ec4\u53f7\u6216\u8005\u7ec4\u6807\u793a\u3002\u770b\u4e00\u4e0b<code>wp-content\/plugins\/wp-syntax\/geshi\/geshi<\/code>\u76ee\u5f55\u4e0b\u67d0\u79cd\u8bed\u8a00\u76f8\u5e94\u7684PHP\u6587\u4ef6\u5c31\u53ef\u4ee5\u77e5\u9053\u6bcf\u4e2a<code>$group<\/code>\u5bf9\u5e94\u54ea\u4e9btoken\u3002\u62ff<code>php.php<\/code>\u4e3a\u4f8b\uff0c\u5173\u952e\u5b57\u4e2d<code>$group=1<\/code>\u5bf9\u5e94&#8217;as&#8217;, &#8216;break&#8217;, &#8216;case&#8217;\u7b49\uff1b\u800c<code>$group=2<\/code>\u5bf9\u5e94&#8217;namespace&#8217;, &#8216;new&#8217;, &#8216;private&#8217;, &#8216;public&#8217;\u7b49\uff1b<code>$group=3<\/code>\u5219\u5bf9\u5e94PHP\u7684\u5185\u90e8\u51fd\u6570\u3002<\/p>\n<p><code>$styles<\/code>\u662f\u9700\u8981\u8bbe\u7f6e\u7684CSS\u6837\u5f0f\uff0c\u5e38\u7528\u7684\u53ea\u8981\u8bbe\u7f6e\u4e00\u4e0b\u989c\u8272\u5c31\u884c\u4e86\u3002<\/p>\n<p><code>$preserve_defaults<\/code>\u662f\u4e00\u4e2aboolean\u503c\uff0c\u8868\u660e\u73b0\u5728\u8bbe\u7f6e\u7684\u6837\u5f0f\u662f\u4e0d\u662f\u8981\u5728\u7ee7\u627f\u9ed8\u8ba4\u6837\u5f0f\u7684\u57fa\u7840\u4e0a\u8fdb\u884c\u6539\u52a8\u3002\u9ed8\u8ba4\u503c\u4e3afalse\uff0c\u5373\u91cd\u65b0\u8bbe\u7f6e\u3002<\/p>\n<p>\u4e0b\u9762\u9644\u4e0a\u4e00\u6bb5\u6211\u5728Unborn\u4e3b\u9898\u4e2d\u4f7f\u7528\u7684\u914d\u8272\u65b9\u6848\u8bbe\u7f6e\u4ee3\u7801\uff1a<\/p>\n<pre lang=\"php\" line=\"1\">function my_custom_geshi_styles(&amp;$geshi)\n{\n    $geshi-&gt;set_overall_style('color: #FFF; font-family:\"Consolas\",monospace,\"Courier New\"');\n    $geshi-&gt;set_brackets_style('color: #CCC;', true); \/\/\u62ec\u53f7\u989c\u8272\n    $geshi-&gt;set_keyword_group_style(1, 'color: #70B9EF;'); \/\/\u7b2c\u4e00\u7ec4\u5173\u952e\u5b57\n    $geshi-&gt;set_keyword_group_style(2, 'color: #996699;'); \/\/\u7b2c\u4e8c\u7ec4\u5173\u952e\u5b57\n    $geshi-&gt;set_keyword_group_style(3, 'color: #FFF;'); \/\/\u7b2c\u4e09\u7ec4\u5173\u952e\u5b57\n    $geshi-&gt;set_methods_style(1, 'color: #FFF;'); \/\/\u7b2c\u4e00\u7ec4\u65b9\u6cd5\u540d\u79f0\n    $geshi-&gt;set_comments_style(1, 'color: #999;'); \/\/\u7b2c\u4e00\u7ec4\u6ce8\u91ca\n    $geshi-&gt;set_comments_style(2, 'color: #33CC66;'); \/\/\u7b2c\u4e8c\u7ec4\u6ce8\u91ca\n    $geshi-&gt;set_comments_style('MULTI', 'color: #999;'); \/\/\u591a\u884c\u6ce8\u91ca\n    $geshi-&gt;set_strings_style('color: #7ACC00;'); \/\/\u5b57\u7b26\u4e32\u76f4\u63a5\u91cf\n    $geshi-&gt;set_strings_style('color: #7ACC00;', false, 'HARD'); \/\/\u5b57\u7b26\u4e32\u76f4\u63a5\u91cf(*)\n    $geshi-&gt;set_regexps_style(0, 'color: #7AB9BE;'); \/\/\u6b63\u5219\u8868\u8fbe\u5f0f\n    $geshi-&gt;set_numbers_style('color: #FFCC00;'); \/\/\u6570\u5b57\n    $geshi-&gt;set_symbols_style('color: #CCC;'); \/\/\u7b26\u53f7\n    $geshi-&gt;set_escape_characters_style('color: #99FF00;'); \/\/\u8f6c\u4e49\u5b57\u7b26\n}<\/pre>\n<p>\u4e0a\u9762\u7ed9\u51fa\u7684\u4ee3\u7801\u4e2d\u6253(*)\u53f7\u7684\u5730\u65b9\u9700\u8981\u6ce8\u610f\uff0c\u6700\u65b0\u7248\u672c\u7684WP-Syntax\u91c7\u7528\u7684GeSHi\u7248\u672c\u53f7\u4e3a<code>1.0.8.3<\/code>\u3002\u8fd9\u4e2a\u7248\u672c\u4e2d\uff0c\u8bbe\u7f6e\u5b57\u7b26\u4e32\u76f4\u63a5\u91cf\u7684\u51fd\u6570\u4e3a<code>set_strings_style($style[, $preserve_defaults])<\/code>\uff0c\u4e5f\u5c31\u662f\u6ca1\u6709\u5bf9\u5b57\u7b26\u4e32\u76f4\u63a5\u91cf\u7684\u7c7b\u522b\u8fdb\u884c\u6307\u5b9a\uff0c\u4e8b\u5b9e\u4e0a\u5728\u8bed\u8a00\u6587\u4ef6\u5982<code>php.php<\/code>\u4e2d\uff0c\u542b\u6709\u6807\u793a\u4e3a&#8221;HARDQUOTE&#8221;\u7684\u4e00\u7ec4\u5b57\u7b26\u4e32\u76f4\u63a5\u91cf\uff0c\u5bf9\u5e94\u4e8e\u7528\u5355\u5f15\u53f7\u5305\u56f4\u7684\u5b57\u7b26\u4e32\u76f4\u63a5\u91cf\uff0c\u8fd9\u4e9b\u4ee3\u7801\u5c31\u65e0\u6cd5\u4f7f\u7528<code>set_strings_style<\/code>\u6765\u8bbe\u7f6e\u5176\u6837\u5f0f\u3002\u6211\u672c\u6765\u60f3\u80fd\u591f\u5728\u4e0d\u6539\u52a8WP-Syntax\u4ee3\u7801\u7684\u60c5\u51b5\u4e0b\u5bf9\u4ee3\u7801\u6837\u5f0f\u8fdb\u884c\u5b8c\u7f8e\u914d\u7f6e\uff0c\u73b0\u5728\u770b\u6765\u662f\u65e0\u6cd5\u8fbe\u6210\u4e86\u3002\u6700\u7ec8GeSHi\u7684BenBE\u7ed9\u6211\u7684\u56de\u590d\u548c\u6211\u60f3\u8c61\u7684\u4e00\u6837\uff0c\u9700\u8981\u4fee\u6539<code>geshi.php<\/code>\u6587\u4ef6\u4e2d\u7684<code>set_strings_style<\/code>\u51fd\u6570\u3002\u5728\u8be5\u6587\u4ef6\u4e2d\u641c\u7d22\u8fd9\u4e2a\u51fd\u6570\u540d\u5e76\u5c06\u4e0b\u9762\u8fd9\u6bb5\u4ee3\u7801\u8986\u76d6\u539f\u6765\u7684\u51fd\u6570\uff0c\u5373\u53ef\u50cf\u6211\u4e0a\u9762\u7ed9\u51fa\u7684\u914d\u7f6e\u90a3\u6837\u4fee\u6539\u8fd9\u7c7b\u4ee3\u7801\u7684\u6837\u5f0f\u3002<\/p>\n<pre lang=\"php\" line=\"1\">function set_strings_style($style, $preserve_defaults = false, $group = 0) {\n    if (!$preserve_defaults) {\n        $this-&gt;language_data['STYLES']['STRINGS'][$group] = $style;\n    } else {\n        $this-&gt;language_data['STYLES']['STRINGS'][$group] .= $style;\n    }\n}<\/pre>\n<p>BenBe\u8bf4GeSHi\u8fd1\u671f\u5c06\u4f1a\u6709\u4e00\u4e2a\u65b0\u7684release\uff0c\u5c06\u89e3\u51b3\u4e0a\u9762\u8fd9\u7c7b\u95ee\u9898\u3002\u5982\u679cWP-Syntax\u5c4a\u65f6\u8ddf\u8fdb\u7684\u8bdd\u6211\u4eec\u5c31\u53ef\u4ee5\u4e0d\u7528\u6539\u52a8\u63d2\u4ef6\u4ee3\u7801\u6765\u8fdb\u884c\u5b8c\u7f8e\u8bbe\u7f6e\u4e86\u3002<\/p>\n<h4>\u9002\u5408\u767d\u8272\u98ce\u683c\u7684\u914d\u8272\u65b9\u6848<\/h4>\n<p>\u4fee\u6539wp-syntax\/wp-syntax.php\u6587\u4ef6\uff0c\u5728122\u884c\u63d2\u5165\u4e0b\u9762\u5185\u5bb9\u3002<\/p>\n<pre lang=\"php\" line=\"122\">$geshi-&gt;set_overall_style('color: #000000; font-family:\"Consolas\",monospace,\"Courier New\"');\u00a0 \/\/\u9ed8\u8ba4\u989c\u8272\n$geshi-&gt;set_brackets_style('color:#CCB;background-color:#F0F0F0', true); \/\/\u62ec\u53f7\u989c\u8272\n$geshi-&gt;set_keyword_group_style(1, 'color: #9400D3;font-weight: bold;'); \/\/\u7b2c\u4e00\u7ec4\u5173\u952e\u5b57 new public class\n$geshi-&gt;set_keyword_group_style(2, 'color: #DC143C;'); \/\/\u7b2c\u4e8c\u7ec4\u5173\u952e\u5b57\u00a0 true\n$geshi-&gt;set_keyword_group_style(3, 'color: #436EEE;'); \/\/\u7b2c\u4e09\u7ec4\u5173\u952e\u5b57 Object ThreadLocal\n$geshi-&gt;set_methods_style(1, 'color: #B8860B;'); \/\/\u7b2c\u4e00\u7ec4\u65b9\u6cd5\u540d\u79f0\n$geshi-&gt;set_comments_style(1, 'color: #777777;'); \/\/\u7b2c\u4e00\u7ec4\u6ce8\u91ca\n$geshi-&gt;set_comments_style(2, 'color: #33CC66;'); \/\/\u7b2c\u4e8c\u7ec4\u6ce8\u91ca\n$geshi-&gt;set_comments_style('MULTI', 'color: #008B45;'); \/\/\u591a\u884c\u6ce8\u91ca\n$geshi-&gt;set_strings_style('color: #00CD00;'); \/\/\u5b57\u7b26\u4e32\u76f4\u63a5\u91cf\n$geshi-&gt;set_strings_style('color: #00CD00;', false, 'HARD'); \/\/\u5b57\u7b26\u4e32\u76f4\u63a5\u91cf(*)\n$geshi-&gt;set_regexps_style(0, 'color: #000088;'); \/\/\u6b63\u5219\u8868\u8fbe\u5f0f\n$geshi-&gt;set_numbers_style('color: #A52A2A;'); \/\/\u6570\u5b57\n$geshi-&gt;set_symbols_style('color: #4A708B;'); \/\/\u7b26\u53f7\n$geshi-&gt;set_escape_characters_style('color: #99FF00;'); \/\/\u8f6c\u4e49\u5b57\u7b26<\/pre>\n<p>\u6587\u7ae0\u6765\u6e90\uff1a<a href=\"http:\/\/lync.in\/customizing-wp-syntax-code-styles\/\">http:\/\/lync.in\/customizing-wp-syntax-code-styles\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5728Wordpress\u4e0b\uff0cWP-Syntax\u662f\u4e00\u6b3e\u975e\u5e38\u4f18\u79c0\u7684\u4ee3\u7801\u9ad8\u4eae\u663e\u793a\u63d2\u4ef6\uff0c\u5b83\u5c06\u5f00\u6e90\u7684\u4ee3\u7801\u9ad8\u4eae\u5de5\u5177GeSHi\u5e94 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[6],"tags":[],"_links":{"self":[{"href":"http:\/\/ynxp.net\/index.php?rest_route=\/wp\/v2\/posts\/80"}],"collection":[{"href":"http:\/\/ynxp.net\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/ynxp.net\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/ynxp.net\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/ynxp.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=80"}],"version-history":[{"count":0,"href":"http:\/\/ynxp.net\/index.php?rest_route=\/wp\/v2\/posts\/80\/revisions"}],"wp:attachment":[{"href":"http:\/\/ynxp.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=80"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/ynxp.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=80"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/ynxp.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=80"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}