WordPress code highlight plug-in: WP-Syntax

Source: Internet
Author: User
There are many WordPress code highlighting plug-ins, such as WP-CodeBox and WP-Syntax. However, if Windows livewriter (WLW for short) is used to publish articles containing code, the code will be escaped.

There are many WordPress code highlighting plug-ins, such as WP-CodeBox and WP-Syntax. However, if you use Windows Live Writer (WLW for short) to publish articles containing code, the code will be escaped and you need to re-edit the code in Html mode on the WordPress background, which is very troublesome. To prevent escaping, you can add the escaped = "true" attribute. after testing, we found that the WP-CodeBox plug-in does not support the escaped = "true" attribute, but WP-Syntax is supported.

Because WP-CodeBox uses

Container, so you 'd better find the same 
The container plug-in finally selects the WP-Syntax code highlight plug-in. both WP-Syntax and WP-CodeBox are syntaxes based on languages supported by GeSHi. the usage is basically the same, most importantly, WP-Syntax supports the escaped = "true" attribute. 

WP-Syntax code writing format
 
// Add the code here ......

Here, lang = "html" indicates that the code language is html. please modify it as needed; line = "1" indicates that the line number is displayed. if not, remove it; escaped = "true" is used to prevent code escaping. if not, remove it.

Note: to use code highlighting plug-ins such as WP-Syntax in the wordpress background, you need to add code in html mode. do not switch to visualization mode at will; otherwise, the code will be easily escaped !!

Highlighted language supported by WP-Syntax plug-in
'actionscript' => array('as'),'ada' => array('a', 'ada', 'adb', 'ads'),'apache' => array('conf'),'asm' => array('ash', 'asm', 'inc'),'asp' => array('asp'),'bash' => array('sh'),'bf' => array('bf'),'c' => array('c', 'h'),'c_mac' => array('c', 'h'),'caddcl' => array(),'cadlisp' => array(),'cdfg' => array('cdfg'),'cobol' => array('cbl'),'cpp' => array('cpp', 'hpp', 'C', 'H', 'CPP', 'HPP'),'csharp' => array('cs'),'css' => array('css'),'d' => array('d'),'delphi' => array('dpk', 'dpr', 'pp', 'pas'),'diff' => array('diff', 'patch'),'dos' => array('bat', 'cmd'),'gettext' => array('po', 'pot'),'gml' => array('gml'),'gnuplot' => array('plt'),'groovy' => array('groovy'),'haskell' => array('hs'),'html4strict' => array('html', 'htm'),'ini' => array('ini', 'desktop'),'java' => array('java'),'javascript' => array('js'),'klonec' => array('kl1'),'klonecpp' => array('klx'),'latex' => array('tex'),'lisp' => array('lisp'),'lua' => array('lua'),'matlab' => array('m'),'mpasm' => array(),'mysql' => array('sql'),'nsis' => array(),'objc' => array(),'oobas' => array(),'oracle8' => array(),'oracle10' => array(),'pascal' => array('pas'),'perl' => array('pl', 'pm'),'php' => array('php', 'php5', 'phtml', 'phps'),'povray' => array('pov'),'providex' => array('pvc', 'pvx'),'prolog' => array('pl'),'python' => array('py'),'qbasic' => array('bi'),'reg' => array('reg'),'ruby' => array('rb'),'sas' => array('sas'),'scala' => array('scala'),'scheme' => array('scm'),'scilab' => array('sci'),'smalltalk' => array('st'),'smarty' => array(),'tcl' => array('tcl'),'vb' => array('bas'),'vbnet' => array(),'visualfoxpro' => array(),'whitespace' => array('ws'),'xml' => array('xml', 'svg'),'z80' => array('z80', 'asm', 'inc')
WP-Syntax installation and use

Official Download WP-Syntax | Download WP-Syntax for backup | you can also search and install it in the background.

WP-Syntax optimization skills

The css style of WP-Syntax looks ugly, so I modified it.
If you need, you can use the following code to overwrite the wp-syntax/wp-syntax.css code for this plug-in

 .wp_syntax {color:#100;background-color:#f9f9f9;border:1px solid #EBEBEB;margin:0 0 1.5em 0;overflow:auto;}.wp_syntax {overflow-x:auto;overflow-y:hidden;padding-bottom:expression(this.scrollWidth > this.offsetWidth ? 15:0);width:99%;}.wp_syntax table {border:none;border-collapse:collapse;margin:0;padding:0;width:100% !important}.wp_syntax caption {padding:2px;width:100%;background-color:#def;text-align:left;font-family:Monaco;font-size:13px;line-height:20px;}.wp_syntax caption a {color:#1982d1;text-align:left;font-family:Monaco;font-size:13px;line-height:20px;text-decoration:none;}.wp_syntax caption a:hover {color:#1982d1;text-decoration:underline;}.wp_syntax div,.wp_syntax td {border:none;text-align:left;padding:0;vertical-align:top;}.wp_syntax td.code {background:none;line-height:normal;white-space:normal;padding-left:10px;}.wp_syntax pre {background:transparent;margin:0;padding:0;width:auto;float:none;clear:none;overflow:visible;font-family:Monaco;font-size:13px;line-height:20px;white-space:pre;}.wp_syntax td.line_numbers pre {border-right:3px solid #6CE26C;background-color:#E7E5DC;color:gray;width:20px;padding:0 5px;text-align:right;}

You can also add the above code to the style.css file of your topic, and then in functions. add the following code in php to cancel the css file loaded by WP-Syntax. in this way, you can retain your own style even if you upgrade the plug-in later.

 if ( has_action( 'wp_print_styles', 'wp_syntax_style' ) ) {remove_action( 'wp_print_styles', 'wp_syntax_style' );};

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.