CodeColorer

Posted by Dmytro Shteflyuk on

CodeColorer is the plugin which allows you to insert code snippets into the post with nice syntax highlighting. I want to show you example first:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
class Feed < ActiveRecord::Base

  SourceTypes = {
    :category => 0,
    :tag => 1
  }
 
  define_enum :source_type, :raise_on_invalid => true

  #-------------------------------------------------
  # Accessors

  def video_ids
    v = self[:video_ids]
    v ? v.split(':').map(&:to_i) : []
  end
end

Plugin based on GeSHi library, which supports most languages. CodeColorer has various nice features:

  • syntax highlighting in RSS feeds
  • syntax highlighting of single line of code (inline)
  • syntax highlighting of code in comments
  • line numbers
  • automatic links to the documentation inserting
  • code block intelligent scroll detection (short code would have short block, for long one block height would be fixed and scrollbar would appear)
  • predefined color themes (Slush & Poppies, Blackboard, Dawn, Mac Classic, Twitlight, Vibrant Ink)
  • syntax colors customization in CSS file
  • code protect from mangling by WordPress (for example, quotes, double-dashes, etc would look just right as you entered)

Installation

  1. Download and unpack plugin files to wp-content/plugins/codecolorer directory.

  2. Enable CodeColorer plugin on your Plugins page in Site Admin.

  3. Go to the Options/CodeColorer page in Site Admin and change plugin’s options as you wish.

  4. Use [cc lang="lang"]code[/cc] or <code lang="lang">code</code> syntax to insert code snippet into the post (you could skip lang="lang", in this case code would be in code block, but without syntax highlighting). Also you can use [cci lang="lang"]code[/cci] to format inline code (see the “inline” option description). The list of available languages you could find below.

  5. Have fun!

Syntax

To insert code snippet into your post (or comment) you should use [cc lang="lang"]code[/cc] or <code lang="lang">code</code> syntax. Starting from version 0.6.0 you could specify additional CodeColorer options inside [cc] tag:

1
[cc lang="php" tab_size="2" lines="40"]// some code[/cc]
Note: You should always use double quotes or single quotes around the parameter value. Boolean values could be passed using string true or false, on or off, number 1 or 0.

Short codes

Starting from CodeColorer 0.8.6 you can use short codes to insert code snippets. The short code in common looks like [ccMODE_LANG], where LANG is your programming language, and MODE is the one or more of following modes:

  • iinline
  • eescaped
  • sstrict
  • nline_numbers
  • bno_border
  • wno_wrap
  • lno_links

Small letter means enabled, capital – disabled. Examples:

PHP code with links enabled and line numbers disabled:

1
2
3
[cclN_php]
echo "hello"
[/cclN_php]

Already escaped HTML code:

1
[ccie_html]<html>[/ccie_html]

Ruby code without wrapping having tab size equal to 4:

1
2
3
[ccW_ruby tab_size="4"]
attr_accessor :title
[/ccW_ruby]

More examples could be found on the CodeColorer Examples page. You can find modes explained below.

Possible parameters

  • lang (string) – source language.
  • tab_size (integer) – how many spaces would represent TAB symbol.
  • line_numbers (boolean) – when true line numbers will be added.
  • first_line (integer) – a number of the first line in the block.
  • highlight (string) – a comma-separated list of line numbers to highlight (e.g. 1,5,8,9).
  • no_links (boolean) – when false keywords will be represented as links to manual.
  • lines (integer) – how many lines would be block height without scroll; could be set to -1 to remove vertical scrollbar.
  • width (integer or string) – block width.
  • height (integer or string) – height in pixels; used when lines number is greater then “lines” value.
  • rss_width (integer or string) – block width in RSS feeds.
  • theme (string) – color theme (default, blackboard, dawn, mac-classic, twitlight, vibrant).
  • inline (boolean) – when true forces code block to render inside <code></code> tag. Used to paste a single line of code into the regular text.
  • strict (boolean) – when true strict mode will be enabled. By default CodeColorer tries to guess whether strict mode is needed, so this option allows to force it on or off when automatic suggestion is wrong.
  • nowrap (boolean) – when false no horizontal scrollbar will be shown; instead code will be wrapped in the end of code box.
  • noborder (boolean) – when true no border will be shown around the code block.
  • no_cc (boolean) – when true the syntax in code block will not be highlighted, code will be rendered inside <code></code> tag.
  • class (string) – additional CSS classes to add to the wrapper HTML element.

You can use special tag [cci] instead of [cc] to force inline mode: [cci lang="lang"]code[/cci]

Most of these parameters could be configured via the CodeColorer options page.

Supported languages

Here is list of supported by CodeColorer languages: abap, actionscript, actionscript3, ada, apache, applescript, apt_sources, asm, asp, autoit, avisynth, bash, basic4gl, bf, bibtex, blitzbasic, bnf, boo, c, c_mac, caddcl, cadlisp, cfdg, cfm, cil, cmake, cobol, cpp-qt, cpp, csharp, css, d, dcs, delphi, diff, div, dos, dot, eiffel, email, erlang, fo, fortran, freebasic, genero, gettext, glsl, gml, gnuplot, groovy, haskell, hq9plus, html4strict, idl, ini, inno, intercal, io, java, java5, javascript, kixtart, klonec, klonecpp, latex, lisp, locobasic, lolcode, lotusformulas, lotusscript, lscript, lsl2, lua, m68k, make, matlab, mirc, modula3, mpasm, mxml, mysql, nsis, oberon2, objc, ocaml-brief, ocaml, oobas, oracle11, oracle8, pascal, per, perl, php-brief, php, pic16, pixelbender, plsql, povray, powershell, progress, prolog, properties, providex, python, qbasic, rails, rebol, reg, robots, ruby, sas, scala, scheme, scilab, sdlbasic, smalltalk, smarty, sql, tcl, teraterm, text, thinbasic, tsql, typoscript, vb, vbnet, verilog, vhdl, vim, visualfoxpro, visualprolog, whitespace, whois, winbatch, xml, xorg_conf, xpp, yaml, z80.

Requirements

Plugin works with WordPress 2.7.0 – 2.8.2 as well. Hey users of WordPress 2.7.0, could you explain why do you use so old buggy crap? Use new one instead, at least it looks more beautiful!

Download

The latest version of the CodeColorer plugin is 0.9.11, and you can download it here:

version0.9.11DownloadCodeColorer Plugin

Also you can download older versions from plugin home page on WordPress.org (but do you really need this old stuff?).

Translations

Thank you all guys, who submitted translations to your language. CodeColorer is currently available in following languages:

Want to help me with translation? It’s easy!

  1. Install Poedit.

  2. Download codecolorer.pot file.

  3. Click File/New catalog from .pot file and select codecolorer.pop you’ve just downloaded.

  4. Enter project name (something like CodeColorer 0.9.8), your name and email address, select a language you want to translate to and click OK.

  5. Enter a filename like codecolorer-en_EN.po and click Save.

  6. Translate all strings one by one.

  7. Send me a .po file with a translation to [email protected]. Do not forget a link to add to CodeColorer project home page.

  8. Thank you!

To fix existing translation, just open corresponding .po file from codecolorer/languages folder in Poedit, and add missing or update existing strings.

Customization

Syntax coloring is highly customizable: you could change color scheme for all
languages or for specific language. You could find CodeColorer CSS in
wp-content/plugins/codecolorer/codecolorer.css file. To change colors for
all languages edit lines below Color scheme section.

There is simple mapping exists between Textmate color themes and CodeColorer
ones:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
    /* "Slush & Poppies" color scheme (default) */
    .codecolorer-container, .codecolorer { color: #000000; background-color: #F1F1F1; }
    /* Comment */
    .codecolorer .co0, .codecolorer .co1, .codecolorer .co2, .codecolorer .co3, .codecolorer .co4, .codecolorer .coMULTI { color: #406040; font-style: italic; }
    /* Constant */
    .codecolorer .nu0, .codecolorer .re3 { color: #0080A0; }
    /* String */
    .codecolorer .st0, .codecolorer .st_h, .codecolorer .es0, .codecolorer .es1 { color: #C03030; }
    /* Entity */
    .codecolorer .me1, .codecolorer .me2 { color: #0080FF; }
    /* Keyword */
    .codecolorer .kw1, .codecolorer .kw2, .codecolorer .sy1 { color: #2060A0; }
    /* Storage */
    .codecolorer .kw3, .codecolorer .kw4, .codecolorer .kw5, .codecolorer .re2 { color: #008080; }
    /* Variable */
    .codecolorer .re0, .codecolorer .re1 { color: #A08000; }
    /* Global color */
    .codecolorer .br0, .codecolorer .sy0 { color: #000000; }

Check the codecolorer.css file to get more examples.

Frequently Asked Questions

Q. How do I can customize CodeColorer CSS rules?
A. Go to the Options/CodeColorer page in Site Admin and change the “Custom CSS Styles” option.

Q. I see &lt; instead of < (or other HTML entities like >, &, ") in my code.
A. You should use [cc escaped="true"] or [cce] in the visual editor when inserting code into the post.

Q. Does it highlights my code on server or client side?
A. CodeColorer performs code highlighting on the server, you could see HTML of the highlighted code in page source.

Q. Is it produces valid XHTML source?
A. Yes, resulting XHTML is completely valid.

Q. Could my visitors insert their code snippets in comments?
A. Yes, CodeColorer supports code highlighting in comments using the same syntax, as you use in your blog posts.

Q. How can I disable syntax highlighting for a particular <code> block?
A. Use no_cc="true" option for your code block.

Q. I have updated the plugin to the newest version and now I keep getting following warnings:

1
Warning: array_keys() [function.array-keys]: The first argument should be an array in /home/wordpress/wp-content/plugins/codecolorer/lib/geshi.php on line 3599

A. Remove all files from wp-content/plugins/codecolorer folder and unpack an archive with plugin again (thanks to Anatoliy ‘TLK’ Kolesnick).

Q. I love this plugin. How to do a favor to the author?
A. Just vote for this plugin on WordPress.org. And thank you!

Support

If you have any suggestions, found a bug, wanted to contribute a
translation to your language, or just wanted to say “thank you”,– feel free to contact me. Promise, I will answer to every message.

If you want to contribute your code, see the Development section below.

Development

Sources of this plugin are available both in SVN and Git:

Feel free to check them out, make your changes and send me patches. Promise, I will apply every patch (of course, if they add a value to the product). Email for patches, suggestions, or bug reports: [email protected]. Also you have much more ways to contact me.

Changelog

  • 0.9.11 (August 8, 2017)
    • Fixed an issue with TinyMCE when CodeColorer options were removed in the editor (thanks to Jonathan Stassen for the suggestion).
    • New art for the WordPress plugins page.
    • Moved translations to https://translate.wordpress.org/projects/wp-plugins/codecolorer. WordPress should automatically download language packs now.
    • Lots of code style issues, should resolve all warnings in PHP logs.
  • 0.9.10 (July 28, 2017)
    • Fixed a bug with large code blocks margins.
    • Added Portuguese translation (thanks to Luis Coutinho).
    • Added Indonesian translation (thanks to Masino Sinaga).
    • Fixed PHP 7 compatibility issues (thanks to Steve Kamerman and Robert Felty).
    • Fixed WordPress 4+ compatibility (editor button, settings page layout).
    • Added “Solarized Light” and “Solarized Dark” themes (thanks to Matt Kirman).

Complete changelog could be found on the CodeColorer History page.

Other plugins

Full list of plugins I have implemented is available here.

228 Responses to this entry

Subscribe to comments with RSS or TrackBack to 'CodeColorer'.

said on July 24th, 2009 at 01:17 · Permalink · Reply

Думаю, стоит добавить параметр:
* Минимальное количество строк для активации “показа номера строк”

А то когда 1-3 строки, то выводить номер строки как-то не актуально…

said on July 24th, 2009 at 02:01 · Permalink · Reply

2adw0rd: В WordPress 2.8 переработали систему безопасности, и теперь добавлять страницы настроек можно только из action’а admin_menu (раньше работало и из admin_init).

А насчет отключения номеров строк — с новыми короткими кодами, имхо, проблема разрешилась сама собой.

1
[ccN_php]тут код без номеров строк[/ccN_php]

Про короткие коды пока что можно почитать здесь, завтра обновлю эту страницу (и переведу на русский).

ЗЫ. В ближайшие дни готовится масштабное обновление (сильно переписан движок и исправлена туча мелких ошибок).

said on July 24th, 2009 at 09:00 · Permalink · Reply
В WordPress 2.8 переработали систему безопасности, и теперь добавлять страницы настроек можно только из action’а admin_menu (раньше работало и из admin_init).

Спасибо!

Я юзаю включение номера строк так: line_numbers="true" и меня устраивает :)

Jürgen
said on July 29th, 2009 at 14:03 · Permalink · Reply

Just a simple question:
How can I define the fontstyle, such as size and face?
Thanks for your reply.
Jürgen

said on July 31st, 2009 at 21:43 · Permalink · Reply

Слушай, я думаю необходимо исключать подгрузку всех css-стилей, когда нужен только один.

/wp-content/plugins/codecolorer/codecolorer.css

said on August 1st, 2009 at 19:12 · Permalink · Reply

Очень хороший плагин, спасибо.
Но у меня недавно возникла проблема… вместо подсвеченного кода появилась строка ::CODECOLORER_BLOCK_1::… до вчерашнего дня было все нормально… обновился и появился этот текст.

Версия WP – 2.8.2–ru

Erik
said on August 1st, 2009 at 22:00 · Permalink · Reply

Hi,

Is it possible to set a default language? Or would it be possible to make it such that a [cc] tag remembers the settings from the previous [cc] tag on the same page so we just have to define it somewhere once?

Jürgen
said on August 3rd, 2009 at 14:11 · Permalink · Reply

Hallo,
is that the answer for my question?
I’m so sorry, i can’t understand any of your russian??? language.
OK, maybe you mean, I have to edit the codecolorer.css.
Can you give me some hints where in the Codecolorer.css-file i have to edit.
Thanks Jürgen

Thomas
said on August 10th, 2009 at 15:04 · Permalink · Reply

Hi,

all I get from CodeColorer is this one line:

::CODECOLORER_BLOCK_1::

The actual code is not printed; looks pretty much like comment #9 from Mad Chicken. I am using CodeColorer 0.9.2 on WP 2.8.3. Any idea?

Thanks in advance
Thomas

said on August 11th, 2009 at 07:10 · Permalink · Reply

The plugins doesn’t work as expected in WordPress-mu… don’t know if missconfiguration or what, but the editor everytime I try to add code (pasted or by keyboard), translates the special characters like < or " to entities… and the result page is showed with the entities…

said on August 14th, 2009 at 19:38 · Permalink · Reply

I send you polish translation of CodeColorer – let me know if everything is ok.

Anon
said on August 16th, 2009 at 02:53 · Permalink · Reply

If you get this ::CODECOLORER_BLOCK_1::, you must use PHP 5 on MediaTemple servers…

ctapmex
said on August 19th, 2009 at 10:18 · Permalink · Reply

Привет.
что то не могу разобраться с tab. как его вставить в визуальный редактор? вставляю код из VS2008 , там точно таб стоит перед строкой. но при сохранении и табы и пробелы удаляются. wp 2.84

ctapmex
said on August 19th, 2009 at 10:47 · Permalink · Reply

хотя, это кажется глюк оперы и tinymce
в ie все отлично

said on August 22nd, 2009 at 14:35 · Permalink · Reply

Hey, thanks for the nice plugin, but it looks like CodeColorer is broken for wordpress 2.8.4 At least all I’m getting is ::CODECOLORER_BLOCK_1:: where I expect a snippet of code.

Is this a known problem?

said on August 25th, 2009 at 18:07 · Permalink · Reply

i would like to know if you would address this error which for the mysql link is wrong??

3Q.

Bughunter
said on August 25th, 2009 at 18:50 · Permalink · Reply

Concerning the error message ‘compilation failed…’ using PHP < 4.3.3 you need an older version of Geshi (1.0.6 seems to work)

said on August 28th, 2009 at 17:51 · Permalink · Reply

First of all, love the plugin, just one ‘request’ allow us to specify the starting line number with the CC tag.

i.e.

1
2
3
4
<?PHP
$changeme = 1;
$butnotme = 2;
?>

You should change line 2 not line 3

Change this

1
$changeme = 1;
said on September 9th, 2009 at 02:19 · Permalink · Reply

Hi! First of all, thanks for the great plugin. I’ve just got one problem with it: no matter what I do, WordPress seems to be stripping the spaces from the start of each line of my code, so that:

class Foo {
function bar() { }
function baz() { }
function quux() {
doFoo();
}
}

comes out as:

class Foo {
function bar() { }
function baz() { }
function quux() {
doFoo();
}
}

The only way around this seems to be to use a tag, but this then messes up the formatting. What should I do?

@Buzz: There is already support to do that: see the “first_line” parameter.

said on September 9th, 2009 at 02:22 · Permalink · Reply

Well this went wrong here too. Let me try again:

1
2
3
4
5
6
7
class Foo {
  function bar() { }
  function baz() { }
  function quux() {
    doFoo();
  }
}

is what I intend, but:

1
2
3
4
5
6
7
class Foo {
function bar() { }
function baz() { }
function quux() {
doFoo();
}
}

is the output I get (when using the visual editor and either the “cc_php” or “cce_php” shortcodes.

said on October 15th, 2009 at 18:30 · Permalink · Reply

Any advice on using CodeColorer with the TinyMCE Advanced visual editor?

Seems that I get either my code right, or my paragraphs right… but not both.

I saw you had a TinyMCE plugin, but have revoked it, any thoughts on re-entering it into the codebase?

BTW:

1
echo "BIG THANKS!";
said on October 16th, 2009 at 12:08 · Permalink · Reply

Yep, TinyMCE editor is a big problem for now. I’ve started working on a TinyMCE plugin for CodeColorer, but this functionality has been disabled due to weird bugs in markup produced by rich editor. Hope, it will be fixed

said on October 16th, 2009 at 12:22 · Permalink · Reply

I’m so sorry .

But i didn’t see the answer of the question “mysql link wrong” ..

dr34m3r
said on October 24th, 2009 at 17:32 · Permalink · Reply

This is the best code highlighter plugin of all. Just voted for the plugin at wordpress.org. My highest appreciation to you my friend. Thanks a lot for this plugin.

said on November 4th, 2009 at 00:11 · Permalink · Reply

[…] 2009, under Uncategorized Just found and installed the CodeColour plugin by Dmytro Shteflyuk (See here and (no I’ve no idea how to pronounce his name either ). It’s easy to find in the […]

said on November 17th, 2009 at 22:06 · Permalink · Reply

Thanks for the wonderful add-in.

I’m having a little problem. When I’m checkin the post page, the add-in works fine. However, I’m having problems on my main page where the cc blocks appear instead.

Also, I tried us the VB language and the comment don’t seem to be recognized.

Sébastien

Tsalagi
said on December 24th, 2009 at 05:10 · Permalink · Reply

Is this plugin supported on this website. If so I need some solutions to two issues.
1. When I use <code> it removes my text from my page.
2. When I set a theme I still get no colors on the code on my page.

Thanks in advance.

Tsalagi
said on December 24th, 2009 at 05:12 · Permalink · Reply

Try again.
1. When I use no_cc="true" my text is removed from my page.

said on December 24th, 2009 at 15:23 · Permalink · Reply

Добрый день, подскажите как то можно сделать чтобы когда человек вводит
{code lang=””}тут текст{code} (специально заменил)
не вылазила ошибка, вот такая:

1
<code>тут текст<code>

У меня стоит последняя 0.9.7 версия, версия WordPress 2.7.1

said on December 24th, 2009 at 15:25 · Permalink · Reply

странно у вас не появилась ошибка, у меня пишет:

1
GeSHi Error: GeSHi could not find the language (using path /wp-content/plugins/codecolorer/lib/geshi/) (code 2)
Douglas
said on December 29th, 2009 at 05:57 · Permalink · Reply

Hi. There is a problem in your code that appear when yout set an image as background. To verify that creates a “stripe” image (www.stripegenerator.com) and add it as background (in codecolorer.css ) and you will see a continuity break (set the width as 100% in the plugin options). I searched in the code and I saw that the cause is the way that you show the line numbers. You calculate the numbers manually and create a table to show them. So there is a conflict between the end of the table and the rest of the container that you create to apply the user options. I solved in two ways. The simplest is to put a width=”100%” in your second , so the table will fill all the container space.
The second is to use the Geshi methods to show the lines:

1
2
$geshi->start_line_numbers_at($options['first_line']);
$geshi->enable_line_numbers(GESHI_FANCY_LINE_NUMBERS);

deleting the creation of the table.

thanks.

said on December 29th, 2009 at 12:34 · Permalink · Reply

I don’t like Geshi line numbers because when you copy code, browser copies them too. It’s really weird thing, so I ended up with this table implementation. Your point about 100% makes sense, I’ll take a look how it will impact code blocks layout.

said on January 8th, 2010 at 06:58 · Permalink · Reply

Hello Dmytro!

I’ve found a bug in CodeColorer. If I try to set its width to 100%, it goes beyond its container (post or comment wrapper), making the page goes beyond browser’s width and creating an horizontal scroll on it.

To fix it, I’ve added the following styles:

1
2
3
4
5
6
7
8
.codecolorer-container{
    position: relative;
    width: 98%;
}
.codecolorer-container .codecolorer{
    position: absolute;
    top:0;
}

Setting .codecolorer‘s position to absolute “locks” it inside the first HTML element whose position is not static (because its position is based on that element), so setting .codecolorer-container to relative, makes it the element to where .codecolorer will be based.

Just to leave it documented, position allows us to change an element’s original position and area. position: relative; allows us to change it based on its original position. Since no top and left properties are set, they remain on their original position, but .codecolorer now can’t go beyond .codecolorer-container.

IDK if this is the proper way to fix it, but worked for me. Note also that I added width: 98%; to define its width, because the whole idea of using these styles is so that I can use % width.

Using style attibute is not good, a better idea would be use PHP to supply a CSS generated dynamically, it is much more powerful :D

Another tip: I needed to use code highlight in my theme, outside of shortcode filters. To do so, I used GetCodeHighlighted:

1
2
3
4
5
6
if(class_exists('CodeColorer')){
    $codeColorer = &CodeColorer::GetInstance();

    echo $codeColorer->GetCodeHighlighted($string);
   
}

$string is a normal string we use in posts and comments, it can have normal text with HTML and they won’t be highlighted, and we just use normal [ cc][ /cc] <code></code> and anything inside them will be highlighted!

Ah and of course, CodeColorer and WP-CodeBox work together nicely, they don’t share the same tags :D

said on March 23rd, 2010 at 16:56 · Permalink · Reply

First of all, thanks for your suggestion about positioning. I will test in on different environments and then decide what to do.

About highlighting of an arbitrary piece of code: you can use codecolorer_highlight global function. It is defined in codecolorer.php and used just to do that (starting from version 0.9.7).

said on January 28th, 2010 at 00:23 · Permalink · Reply

I have made a modification to the plugin that uses Geshi to background highlight particular lines of already highlighted code. It’s a way of outlining specific lines of some code for tutorial use. The modification is described here.http://www.deltanova.co.uk/641/

said on March 23rd, 2010 at 16:57 · Permalink · Reply

Thank you for your contribution. Just ported back your changes to the CodeColorer repo.

said on April 5th, 2010 at 21:32 · Permalink · Reply

Following the integration of my previous modification into 0.9.8 I was asked by a user to enhance the highlight function to accept number ranges in addition to individual line numbers. The modification can be found here http://www.deltanova.co.uk/670/

said on April 6th, 2010 at 15:34 · Permalink · Reply

Merged your changes to core. Will be released in 0.9.9 (not sure when exactly). Thank you!

said on April 28th, 2010 at 13:08 · Permalink · Reply

Hi,
Great plugin and I use it in my blog.
I wonder is there also function of this plugin to use inside the template and not as a post shortcode?

Thanks,
Maor

DM
said on May 12th, 2010 at 21:52 · Permalink · Reply

Hi Dmytro:

Thanks for such a great plugin!

I have three suggestions, I don’t know if you’ll be interested, but I’ll mention them anyways.

The first suggestion is to make all keyword links

1
rel="external"

or to make it an option (to globally specify the

1
rel

attribute for these links on the options page).

Second, I noticed that the line numbering does not include empty lines at the beginning nor end of a code block. That could be an option to include those empty lines in the numbering too, or not?

And third, if there was a parameter to continue the line numbering from the previous code block on the page, that would be great. When I created my first code post using your plugin (PHP Code: Twitter Location Info), I wanted the line numbers to be sequential, but I had to save the post as a draft each time I wanted to find out what the last line number from the previous block was so that I could continue from there. I couldn’t use the same line numbers from Coda since the empty lines weren’t being included by the plugin…

Anyways, once again, a great plugin – thanks for all your hard work, and thanks for sharing this!

DM

said on May 18th, 2010 at 17:06 · Permalink · Reply

This is the best working code highlighter I have found for WordPress. However, I have an issue where I do a LOT of drafts for my posts. It sometimes takes days, or weeks, of modifying before they actually get published.

There are a few problems:

Tabs are lost when switching from Visual to HTML (or vice-versa).
Code is escaped once switching from Visual to HTML if you use <code>. After it is escaped, you must go back into the HTML, remove <code>, and then return to Visual and apply [cce] or [cc escaped="true"].

The second problem is the most bothersome. I have to copy my code, go into HTML view, paste it into a code block, go into Visual, go into HTML, remove the code block, go into Visual, and then add [cce] or [cc escaped="true"]. This is extremely tedious just to get the formatting right and even then the tabs don’t work properly.

Has anyone found a proposed fix? If it is already in the comments above (as they are so lengthy) could it possibly be noted in the FAQ?

Thanks for any help!

said on August 22nd, 2011 at 08:18 · Permalink · Reply

right now I am using wp-syntax in my site. but I want to switch to this plugin. Problem is that I have already a lots of code blogs added in current posts. Is there any migration available from wp-syntax to code color? That will be a really helpful.

wp-syntax uses the code to format the code.

abugaga
said on September 28th, 2011 at 10:05 · Permalink · Reply

any way to change font size?

said on November 28th, 2011 at 04:10 · Permalink · Reply

hi!

i have this code blok

1
2
3
4
server:/usr/local/src# apt-get build-dep proftpd-dfsg
Reading package lists... Done
Building dependency tree
Reading state information... Done

But i only this text bold: apt-get build-dep proftpd-dfsg

Is possible….?

said on January 26th, 2012 at 21:00 · Permalink · Reply

Thanks for this plugin. I’m trying it out on my own site. But I wondered, since you’ve listed

1
html4strict

as a supported language, what about supporting HTML5?

said on January 30th, 2012 at 18:37 · Permalink · Reply

Hello,

I have recently begun to use ColorCoder for a very large project of mine.
However, I am experiencing a few problems:
One, the formatting does not appear to be correct, for example, here: http://mcode.ca/2012/01/30/basic-system-output-in-java/
Two, more than one space is not recognized within the code, it always defaults to HTML formatting.
Any help would be greatly appreciated.

Thank you.

said on February 15th, 2012 at 17:23 · Permalink · Reply

Great plugin, thanks! And working with latest version of wordpress: 3.3.1

said on February 26th, 2012 at 13:54 · Permalink · Reply

I think Codecolorer need “Show only code” feature, like this:
http://prntscr.com/6hlzu
http://prntscr.com/6hlzz

I did it with jQuery + CSS + Colorbox jQuery plugin

Demo:
http://www.egonomik.com/2012/02/jquery-ile-inputa-girilen-degerleri-es-zamanli-temizlemek/

Javascript:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
// Code colorer
$(".cclink").colorbox({inline:true, width:"600"});
$(".codecolorer-container").live("mouseenter", function() {  
  $(this).find(".ccshow").show();
  $("#ccholder").val("<!-- egonomik.com -->\n"+$(this).text());                          
});

$(".codecolorer-container").live("mouseleave", function() {  
  $(this).find(".ccshow").hide();                          
});

$(".ccshow").live("mouseenter", function() {  
  var myParent = $(this).parent(".codecolorer-container");
  var myCcolor = myParent.find(".codecolorer").text();
  $("#ccholder").val("<!-- egonomik.com -->\n"+myCcolor);                        
});

codecolorer-core.php (line 243):

1
$result = '<div class="' . $css_class . '" ' . $style . '>' . $html . ' <div class="ccshow"><a href="#ccouter" class="cclink">kod</a></div></div>';

Holder div:

1
2
3
4
5
6
<!-- code colorer holder -->
<div style="display:none">
<div id="ccouter">
<textarea id="ccholder" onclick="select();"></textarea>
</div>
</div>

CSS:

1
2
3
4
5
/* ccholder */
#ccholder { width: 100%; height: 300px; font-size: 11px; line-height: 1.5em; font-family: Helvetica, Arial, sans-serif; }
.codecolorer-container { position:relative !important; }  
.ccshow { display:none; position:absolute; right: 0; top: 0; padding: 1px 8px 0 9px; background: #2E2E2E; -webkit-border-bottom-left-radius: 6px; -moz-border-radius-bottomleft: 6px; border-bottom-left-radius: 6px; }
.cclink { display: inline-block; padding: 2px 10px; }
said on May 18th, 2012 at 10:21 · Permalink · Reply

Ask the SQL code should be how to write? [CC lang = “SQL”] wrote wrong?

More comments: 1 2 3 4 5

Post a comment

You can use simple HTML-formatting tags (like <a>, <strong>, <em>, <ul>, <blockquote>, and other). To format your code sample use [cc lang="php"]$a = "hello";[/cc] (allowed languages are ruby, php, yaml, html, csharp, javascript). Also you can use [cc][/cc] block and its syntax would not be highlighted.

Submit Comment