“受限” HTML 文本区域/所见即所得编辑器?

发布于 2024-09-02 00:02:53 字数 255 浏览 4 评论 0原文

我正在寻找一个基于网络的 JavaScript

到目前为止,我见过的编辑器都没有明确支持此功能,除非将其侵入编辑器中。是否有任何编辑器能够开箱即用或通过少量配置来完成此操作?

非常感谢您的任何提示!

I am looking for a web-based JavaScript <textarea> editor with support for standard features like selectable font, text colour, paragraph alignment etc. However, there is one considerable constraint: Formatting should always apply to all the text, not parts of the text. That is, the user is able to colour all of his text red, or all of his text blue, but he shouldn't be allowed to mix and match.

None of the editors I've looked at so far explicitly supported this feature, short of hacking it into the editor. Is any editor out there able to do this out of the box, or with small amounts of configuration?

Thanks a lot for any hints!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

你穿错了嫁妆 2024-09-09 00:02:53

这应该可以通过使用任何所见即所得编辑器、删除所有文本格式化功能并通过操作 body 元素的 CSS 来控制文档的样式来实现:

my_wysiwyg_editor.document.body.style.fontSize = "15px";
my_wysiwyg_editor.document.body.style.color = "blue";

这是如何在 CKEditor 中访问 WYSIWYG 文档(评分最高的答案是正确的 IIRC,我无法接受它,因为它是一个赏金已过期。)

不过,我不保证它会为您解决问题,并且将会有一些怪癖 - 编辑者倾向于将自己的内容添加到 HTML 中(例如将段落包装到 中)

标签等)这可能会让生活变得困难。

如果您不需要某些所见即所得功能,我建议使用普通的文本区域 - 您可以轻松地影响字体大小、颜色等,而且它更简单而不是成熟的所见即所得解决方案。

This should be doable by taking any WYSIWYG editor, removing all text formatting capabilities and controlling the document's style by manipulating the body element's CSS:

my_wysiwyg_editor.document.body.style.fontSize = "15px";
my_wysiwyg_editor.document.body.style.color = "blue";

Here's how to access the WYSIWYG document in CKEditor (the top rated answer is the correct one IIRC, I can't accept it because it was an expired bounty.)

I'm not promising it will work out for you, though, and there will be quirks - the editors tend to add their own stuff to the HTML (e.g. wrap paragraphs into <p> tags and such) which could make life hard.

If you wouldn't need some of the WYSIWYG capabilities, I'd suggest a normal textarea - you can influence that in font size, colour etc. easily and it's way simpler than a full-blown WYSIWYG solution.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文