Drupal: Trying to use GeSHi with CKeditor

1.6k views Asked by At

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: [email protected]
//////////////////////////////////////////////////////////////////////

#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: [email protected]
//////////////////////////////////////////////////////////////////////

#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.

2

There are 2 answers

2
dzogchen On BEST ANSWER

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

2
Peter Petrik On

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.