如何从summernote文本编辑器中派生纯文本(How to derive plain text from summernote text editor)

系统教程 行业动态 更新时间:2024-06-14 16:58:30
如何从summernote文本编辑器中派生纯文本(How to derive plain text from summernote text editor)

我在rails应用程序中使用summernote文本编辑器。 当我在编辑器中输入纯文本时,我会在编辑器中输入的文本旁边获得html标记和其他字符。 我想知道如何在输出中得到纯文本。 我试过这个解决方案,我在网上找到,但我得到一个错误,说'var是一个保留字'

var plainText = $($("#summernote").summernote("code")).text()

这是我咖啡文件中的summernote代码

$ -> $('[data-provider="summernote"]').each -> $(this).summernote height: 300

I am using summernote text editor in a rails app. When I type in plain text in the editor, I get html tags and other characters alongside the text i typed in the editor. I would like to know how i can derive just plain text in the output. I tried this solution i found online but I get an error saying 'var is a reserved word'

var plainText = $($("#summernote").summernote("code")).text()

This is the summernote code in my coffee file

$ -> $('[data-provider="summernote"]').each -> $(this).summernote height: 300

最满意答案

我终于找到了这个问题的简单解决方案,它没有JavaScript。 在编辑器中键入或粘贴文本后,必须清理输出。 举例来说,在你的展示页面中,你就是这样做的

<%= sanitize @job.description %>

然后你毫无麻烦地获得纯文本。 `

I finally found a simple solution to this problem and it is without JavaScript. After typing or pasting text into the editor, you have to sanitize the output. So for example, in your show page, you do

<%= sanitize @job.description %>

Then you derive your plain text without any hassle. `

更多推荐

本文发布于:2023-04-15 03:40:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/dzcp/3c5045c23dd3c995f943dc4acd65123b.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:器中   文本   文本编辑   summernote   editor

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!