用于带有语法着色的 HTML 编辑器的 jQuery 插件

2022-01-11 00:00:00 jquery jquery-plugins javascript

我正在寻找一个 jQuery 插件,它将显示一个用于 HTML 创作的文本区域 &编辑.

I'm looking for a jQuery Plugin that will display a textarea for HTML authoring & editing.

我正在寻找的东西:

  1. 必须支持编写 HTML,而不是所见即所得的表示
  2. 必须像任何富客户端 IDE 一样在键入时为 HTML 着色.
  3. 应该是 jQuery,但原生 JS 也可以.

我玩过 MarkItUp,它可以让我 90% 到达那里,但没有提供语法着色.据我所知,WYMeditor 没有代码视图"选项,而只是一个所见即所得的视图.

I have played with MarkItUp which gets me 90% there but offers no syntax coloring. And WYMeditor as far as I can tell has no option for "code view" and is instead just a WYSIWYG view.

过去有人做过类似的事情吗?

Anybody out there done something like this in the past?

推荐答案

使用 CodeMirror.它是 Google 用于他们的 API 游乐场 的荧光笔.

Use CodeMirror. It's the highlighter used by Google for their API playground.

我试过了,效果很好,根据他们的网站,它可以在以下浏览器中运行:

I've tried it and it works well, and according to their site it works in the following browsers:

  • Firefox 1.5 或更高版本
  • Internet Explorer 6 或更高版本
  • Safari 3 或更高版本
  • Opera 9.52 或更高版本

我不明白你为什么在这种情况下提到 jQuery,因为 jQuery 与你需要做的事情没有任何关系,除了它的选择器引擎可以用来找到你想要启用语法突出显示的文本框(尽管如果你把 id 放在上面,你也不应该需要 jQuery.)

I don't understand why you mention jQuery in this case, since jQuery has nothing relevant to what you need to do, other than its selector engine which could be used to find the textbox you want to enable syntax highlighting for (although if you put an id on it you shouldn't need jQuery for that either.)

最好使用专门设计用于解决手头任务的独立库(CodeMirror 就是这样).您将获得最佳性能,并且开发人员更易于维护,从而确保更好的质量的代码.

It's better to go with a stand-alone library that is especially designed to solve the task at hand (which CodeMirror is.) You'll get maximum performance and it'll be much more maintainable by the developers, ensuring better quality of the code.

相关文章