简体   繁体   English

如何让我们的所见即所得编辑器停止删除 HTML 评论、CSS 类和内联 styles?

[英]How can I get our WYSIWYG editor to stop removing HTML comments, CSS classes and inline styles?

We currently use wysihtml5-rails to let our users edit emails before they are sent but this is not working out so well for a few reasons.我们目前使用 wysihtml5-rails 让我们的用户在发送电子邮件之前对其进行编辑,但由于一些原因,这并不是很好。

I need the comments to allow for Outlook specific comments like these.我需要评论以允许像这样的 Outlook 特定评论。 All comments are being removed, currently.目前正在删除所有评论。

I also need the CSS classes to be untouched as the editor content will be a pre-generated email that includes CSS classes.我还需要保持 CSS 类不变,因为编辑器内容将是预先生成的 email,其中包括 CSS 类。 Our editor will only keep classes that are whitelisted but this is annoying as we need to update that list with every change.我们的编辑器只会保留列入白名单的类,但这很烦人,因为我们需要在每次更改时更新该列表。

Same goes for inline styles.内联 styles 也是如此。 Some of the styles in the generated email are inline instead of in classes.生成的 email 中的一些 styles 是内联的,而不是类中的。 Those need to be kept but they are being removed.这些需要保留,但正在被删除。

Is there any way I can get our editor to work this way?有什么办法可以让我们的编辑器以这种方式工作吗?

I found a solution but it's hacky.我找到了一个解决方案,但它很hacky。

I realized that the raw HTML was being stored on the page in a hidden textarea tag.我意识到原始 HTML 被存储在页面上的隐藏文本区域标签中。 Interestingly, all the elements that I needed (CSS classes, comments) were still there.有趣的是,我需要的所有元素(CSS 类、注释)仍然存在。 But when submitting the form, the value of this textarea was replaced with the parsed results from the editor which gets sent to the server.但是在提交表单时,这个 textarea 的值被替换为来自编辑器的解析结果,该结果被发送到服务器。 All the comments and classes are gone from this text.所有的评论和类都从这个文本中消失了。

The solution was then to create a second field that takes the unparsed value from the WYSIWYG editor and sends that along.然后解决方案是创建第二个字段,该字段从 WYSIWYG 编辑器获取未解析的值并将其发送。 Easy in rails but just making this new field part of a form.在 Rails 中很容易,但只是让这个新字段成为表单的一部分。 Then the controller can choose which value to take.那么controller可以选择取哪个值。 In my case, I renamed the existing message field to parsed_message .就我而言,我将现有的消息字段重命名为parsed_message Then added a new message field which will hold the unparsed message.然后添加了一个新的消息字段,它将保存未解析的消息。

The WYSIWYG editor we are using allows this by having a method that can be called at any time: window.email_editor.getValue() .我们使用的 WYSIWYG 编辑器通过一个可以随时调用的方法来实现这一点: window.email_editor.getValue() Here the email_editor is the editor instantiated by the javascript on the page.这里的email_editor是页面上 javascript 实例化的编辑器。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM