4

I was hoping to use CKeditor with GeSHi, but I'm having some major difficulties. What happens is, if I create a new piece of content, then, disable CKeditor so I'm just writing plain HTML, I can enclose a code snipptet in <pre> </pre> tags. If I then save, GeSHi does its thing nicely and the snippet looks good.

However, if I then try to edit that piece of content, CKeditor messes around with the formatting of the code, specifically replacing a lot of characters with special escape sequences, and also trying to close what it thinks are HTML tags but are actually C++ include files, e.g. #include <iostream> will make CKeditor place a </iostream> at the end of the text. Then, in the best scenario my code just looks bad.

In other cases, the behaviour's really weird: the page won't load and gives me a server error instead. I assume that's because, server side, some change that CKeditor has made to the code snippet is making GeSHi crash or vice versa.

Here's an example piece of code that looked correct after I entered it verbatim in the plaintext editor and enclosed it in <pre> tags:

// All rights reserved
// Email: firstname.lastname@url.com
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include <iostream>
#include <fstream>

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

myClass::myClass()
{
    m_lthing = NULL;
    m_athing = NULL;
    m_bthing = NULL;

    m_lthingthing = NULL;
    m_athingthing = NULL;
    m_bthingthing = NULL;
}

However, just clicking Edit then Save again without making any changes makes CKeditor mess around with the code, which now looks like this:

// All rights reserved
// Email: firstname.lastname@url.com
//////////////////////////////////////////////////////////////////////

#include &quot;stdafx.h&quot;
#include <iostream>
#include <fstream>

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

myClass::myClass()
{
    m_lthing = NULL;
    m_athing = NULL;
    m_bthing = NULL;

    m_lthingthing = NULL;
    m_athingthing = NULL;
    m_bthingthing = NULL;
}</fstream></iostream>

Does anyone have any thoughts on this, or can anyone recommend a good alternative to the system I'm trying to use now? I'm not super attached to CKeditor or GeSHi, although I've generally been pleased with CKeditor so far, and I like the fact that GeSHi does MATLAB formatting. Also, as per answer/ comment below, I have already tried Peter Petrik's approach outlined here, and the crashing behaviour still occurred.

Thanks.

SSilk
  • 2,433
  • 7
  • 29
  • 44

2 Answers2

5

Which version of Drupal/CKEditor/GeSHi are you using? I'd verify Input Formats (admin/settings/filters) and make sure whichever format you have used doesn't mess your code with additional filters. Also verify allowed HTML tags.

Peter Petrik
  • 429
  • 4
  • 5
  • I'm using Drupal 6.20, CKEditor 6.x-1.2, GeSHi 6.x-1.4. Under Input Formats -> Full HTML, GeSHi is enabled, along with HTML Corrector, Line Break Converter, and URL filter. Under Rearrange, their order from top to bottom is URL, HTML Corrector, Line Break, GeSHi. Does any of the above need changing? Thanks. – SSilk Mar 04 '11 at 02:57
  • Just to be safe, I'd turn off the Line Break Converter and HTML Corrector. Make sure GeSHi filter is highest in the order. Which version of CKEditor itself are you running (not the Drupal module, but the CKEditor library version). – Peter Petrik Mar 06 '11 at 07:36
1

Look at this - it may help ckeditor-and-geshi-filter

dzogchen
  • 383
  • 3
  • 10
  • Sorry, I forgot to mention I tried Petrik's method already. It did not work for me. I think I will try it again though as I'm not sure I did the section "Toolbar button theme" correctly. He does not specify which of the CKeditor theme's three CSS files the code should go in. However, that should not affect CKeditor or GeSHi crashing on parsing code. I think part of the problem is that his list of string replacements is not complete; there seems to be no handling of '&nbsp' inserted by CKeditor, or the closing of CPP include statements as though they were HTML tags. Thanks. – SSilk Feb 24 '11 at 19:52
  • OK, I tried Petrik's method again, and got it working this time. There were a few small details I had jumped over/ misunderstood. It appears to be working now. Thanks. – SSilk Mar 05 '11 at 22:14