【问题标题】:How do I stop the jQuery-Clean plugin from deleting white spaces?如何阻止 jQuery-Clean 插件删除空格?
【发布时间】:2013-03-11 09:15:01
【问题描述】:

我正在使用这个插件:link

像这样:

$('.postListingDescription')
  .html(
    $.htmlClean(description, { 
      allowedTags : ["p", "b", "i", "u", "ul", "li", "a", "strong", "em", "br"] 
    })
  );

不幸的是,这也删除了任何空白,禁止任何段落区分并将所有内容放在一个不返回的长字符串中。有谁知道如何解决这个问题?

【问题讨论】:

  • 听起来您必须预先解析文本并在适当的地方插入<p> 标签。 (或者,至少将换行符变成<br />。)
  • description 的价值是多少?

标签: javascript jquery jquery-plugins


【解决方案1】:

如果没有可用的选项,最简单的方法是替换它(jquery.htmlClean.js 的第 485 行):

function textClean(text) {
        return text
            .replace(/ |\n/g, " ")
            .replace(/\s\s+/g, " ");
    }   

对此:

function textClean(text) {
            return text
        }     

但同样,您不应该使用空格来控制您的布局。
所以你可以做的是用<p>标签替换所有&nbsp,就像在cmets中提到的那样:

$this.html().replace(/\s\s+/g, '<p></p>')

【讨论】:

  • 我认为 replace(/\s+/g, " ") 正是 OP 不想要的
  • @Bergi,我想你可能是对的。我已更新我的答案以删除这两种情况。
猜你喜欢
  • 2015-01-19
  • 2017-09-17
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-04-25
  • 2019-01-02
  • 1970-01-01
  • 2016-09-12
相关资源
最近更新 更多