Drupal:尝试将 GeSHi 与 CKeditor 一起使用
我希望将 CKeditor 与 GeSHi 一起使用,但我遇到了一些重大困难。发生的情况是,如果我创建一个新的内容,然后禁用 CKeditor,这样我就只编写纯 HTML,我可以在 中包含一个代码片段。
标签。如果我随后保存,GeSHi 会很好地完成它的工作,并且片段看起来不错。
然而,如果我随后尝试编辑该内容,CKeditor 会搞乱代码的格式,特别是用特殊的转义序列替换大量字符,并且还尝试关闭它认为是 HTML 标签但实际上是 C++ 的内容文件,例如 #include
将使 CKeditor 在文本末尾放置 。然后,在最好的情况下,我的代码看起来很糟糕。
在其他情况下,行为真的很奇怪:页面不会加载,而是给我一个服务器错误。我认为这是因为,在服务器端,CKeditor 对代码片段所做的一些更改导致 GeSHi 崩溃,反之亦然。
下面是一段示例代码,在我在纯文本编辑器中逐字输入并将其括在
标记中后,该代码看起来是正确的:
// 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;
}
但是,只需单击“编辑”,然后再次单击“保存”而不进行任何更改,会使 CKeditor 变得混乱周围的代码,现在看起来像这样:
// 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;
}</fstream></iostream>
有没有人对此有任何想法,或者有人可以推荐我现在尝试使用的系统的一个好的替代方案吗?我并不是非常喜欢 CKeditor 或 GeSHi,尽管到目前为止我总体上对 CKeditor 很满意,而且我喜欢 GeSHi 进行 MATLAB 格式化。另外,根据下面的答案/评论,我已经尝试过 此处,并且崩溃行为仍然发生。
谢谢。
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 "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;
}</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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您使用的是哪个版本的 Drupal/CKEditor/GeSHi?我会验证输入格式(管理/设置/过滤器),并确保您使用的任何格式都不会因为额外的过滤器而扰乱您的代码。还要验证允许的 HTML 标记。
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.
看看这个 - 它可能会有所帮助ckeditor-and-geshi-filter
Look at this - it may help ckeditor-and-geshi-filter