I recently switched my blog from joomla to wordpress and i'm having problems when posting code snippets.
The editor seems to remove some of the characters when i save my posts.
I am using a plugin that i got from this link: http://alexgorbatchev.com/SyntaxHighlighter/
Example:
<pre class="brush: javascript">;
var window.onload = function() {
alert("Loading is complete");
};
</pre>
Is formatted to:
开发者_JAVA百科<pre>;
var window.onload = function() {
alert("Loading is complete");
};
</pre>
How can i solve this problem?
If you're on WordPress.com, I believe you should be using a shortcode like so: http://en.support.wordpress.com/code/posting-source-code/
If you're on self-hosted WordPress and using the WordPress plugin Syntax Highlighter (http://wordpress.org/extend/plugins/syntax-highlighter/), again I think the correct way to insert code is by wrapping it in a shortcode. So instead of < pre > you would use:
[javascript]
// your code here
[/javascript]
If neither of these sounds like an ideal solution (or works) there are a bunch of other syntax highlighter plugins for self-hosted WordPress that might be better: http://wordpress.org/extend/plugins/search.php?q=syntax+highlighter
Hope this helps - best of luck!
Agree with @Michelle. This actually works for me.
[sourcecode language='javascript']
//Replace 'javascript' by the corresponding language
//Your code goes here
[/sourcecode]
It will work on save or update for hosted and non hosted sites. Example.
To apply it to your text, you just have to switch to the 'Text' visual editor.
Your pages will load faster if you do the syntax highlighting before posting, using pygmentize: http://permafrostcodingstudio.com/articles/syntax-highlighting-in-posts/
It's a little more complicated, but worth being able to disable a plugin. Wordpress will run faster and be more secure with fewer plugins installed.
精彩评论