【问题标题】:How to disable the enriched text of the summernote without activating the codeview mode?如何在不激活codeview模式的情况下禁用summernote的丰富文本?
【发布时间】:2019-08-09 07:40:34
【问题描述】:

下午好。我想得到一个带有HTML标签的文本字符串,但是summernote会解释它们并显示富文本,而我想要的是显示带有标签的文本,但我没有成功:

var content = '<b>Content</b> and <b>tags</b> and <i>HTML</i>';

//I have tried this:
$('#summernote').summernote('code',content);
$('#summernote').val(content);

但结果是这样的:ContenttagsHTML

我想要的是复制和粘贴包含 HTML 标签的文本,但我不希望 Summernote 解释这些标签。我想要的是,用户可以在粘贴该文本时看到标签,而无需激活模式“代码视图”

var content = '<b>Content</b> and <b>tags</b> and <i>HTML</i>';

//Initialize the summernote
$('#summernote').summernote({
  height: 200
});

$('#summernote').summernote('code',content);
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta/css/bootstrap.min.css">
<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.11.0/umd/popper.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta/js/bootstrap.min.js"></script>
<link href="https://cdnjs.cloudflare.com/ajax/libs/summernote/0.8.11/summernote-bs4.css" rel="stylesheet">
<script src="https://cdnjs.cloudflare.com/ajax/libs/summernote/0.8.11/summernote-bs4.js"></script>

<div id="summernote">

</div>

【问题讨论】:

  • 看看pre tag
  • 更改 settings.js
  • 我检查了文件 settings.js 我认为这可能是解决方案。 @Moob
  • 谢谢,可惜没有解决问题。不知道summernote的文本丰富是否可以通过某种方式禁用。

标签: javascript jquery summernote


【解决方案1】:

美好的一天,我已经设法解决了这个问题。

我的目标是在从外部源(单词)粘贴带有 HTML 的内容时,Summernote 不会解释标签,如果它会向我显示一个显示标签的字符串。

类似这样的:

"带有 HTMLhide 标签的文本" ==> "

带有 HTMLhide标记的文本> 标签


"

解决方案是:

  1. 获取复制粘贴的内容

    let contentPasted = $('#summernote').summernote('code');
    
  2. 将符号 (>) 替换为 (& lt; 和 & gt;)

    let finalContent = contentPasted.replace(/>/g,'&gt;').replace(/</g,'&lt;')
    

这样,不解释 HTML 代码就足够了:

【讨论】:

    猜你喜欢
    • 2017-05-24
    • 1970-01-01
    • 2017-12-08
    • 1970-01-01
    • 2021-07-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多