寻找一个与可格式化文本区域简单等效的东西
我创建了一个小 dsl 来查询我们公司的数据库。我现在正在尝试创建一个网络前端。我开始使用文本区域来允许用户输入他们的查询,但最近发现您无法在文本区域中设置文本片段的格式(我会这样做以突出显示查询文本中的错误等)——标签在文本区域中不起作用。
我们已经在 Google Chrome 上进行了标准化,所以我想要一个小部件:
- 看起来
- 可以调整文本区域的大小(如 Chrome 中的文本区域)
- 允许使用标签和类(例如,子字符串)对自身内部的子字符串进行格式化
我不想要的是:
- 工具栏/按钮等
- 复杂的API,以便简单地执行上述操作。
我看过 tinymce,但不知道如何获取文本区域的整个文本,搜索一个子字符串,然后将该子字符串包装在标签中。 (我已经用常规文本区域和 javascript 完成了此操作,所以如果它相似,那就太好了。)
任何指导、想法等,非常感谢。
I have created a little dsl for querying our company database. I am now trying to create a web front end. I began using textareas to allow users to enter their queries, but recently discovered that you can't format pieces of texts within textareas (which I would do to highlight errors in query text, etc) -- tags don't work within a textarea.
We have standardized on Google Chrome, so what I'd like is a widget that:
- looks like a text area
- can be resized (like textareas in Chrome)
- allows formattting of substrings within itself by use of tags and classes (e.g., a substring)
what I don't want:
- toolbars/buttons, etc
- a complex api in order to simply do the above.
I've looked at tinymce, but can't figure out how to get the entire text of the textarea, search for a substring, then wrap that substring in a tag. (I've done this with a regular textarea and javascript, so if it's similar, great.)
Any guidance, ideas, etc, greatly appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果我理解正确,您可以使用带有
contenteditable
属性和一些样式的div
(或其他)元素。然后,您可以在innerHTML
属性中获取带有标记的元素内容,并在textContent
属性中获取纯文本。简单的例子:If I understand you correctly, you could use a
div
(or another) element with thecontenteditable
attribute and some styling. You can then get the element content with markup in theinnerHTML
property and the as plain text in thetextContent
property. Simple example:CKEditor 可能是您的选择。
配置和使用其 API 很容易:
http://ckeditor.com/
http://docs.cksource.com/
您可以创建自己的工具栏,也可以不使用任何工具栏。
CKEditor may be your choice.
It's easy to configure and use its API:
http://ckeditor.com/
http://docs.cksource.com/
You can create your own toolbar or use none.
我强烈建议 CodeMirror (以及 GitHub)。它有大量可用的格式选项,听起来正是您正在寻找的(语法荧光笔)。它是高度可定制的(我已经能够让这个东西为我而努力)并且可以在大量浏览器上运行。
您可以从 MySQL 模式 开始,并根据需要自定义它(我假设当你说查询时,是某种 SQL,但如果我弄错了,其他模式也可以工作)。
要让编辑器自动调整大小,请将以下内容添加到 CSS 中:
I highly suggest CodeMirror (and on GitHub). It has a ton of formatting options already available, and sounds like exactly what you're looking for (a syntax highlighter). It's extremely customizable (I've been able to make this thing bend over backwards for me) and works across a ton of browsers.
You could start out with the MySQL Mode, and customize it as necessary (I'm assuming some sort of SQL when you say query, but other modes could work instead, if I'm mistaken).
To have the editor automatically resize, add the following to your CSS: