无法在Refinery CMS-Rails 4中实现itemprop属性



如果你熟悉Refinery CMS(一种用于Rails的CMS),那就是我不能创建schema.org属性。

我打开一个页面,进行编辑,并声明:

<figure itemscope itemtype="http://schema.org/Person">
    <img src="#" alt="Example"/>
    <figcaption>
          <span itemprop="name">Bobby Orr</span> - CEO of Example.com
    </figcaption>
</figure>

结果是:

<figure>
    <img src="#" alt="Example"/>
    <figcaption>
        <span>Bobby Orr</span> - CEO of Example.com
    </figcaption>
</figure>

有人知道一种方法可以在不删除Refinery的情况下保持模式吗?

您可以将适当的标记添加到config/initializers/reinery/core.rb 中的config.wymeditor_whitelist_tags哈希中

这应该适用于你的数字标签:

config.whitelist_tags = {'figure' => {'attributes' =>{ '1': 'itemscope', '2': 'itemtype'}}}

请注意,如果你走这条路,你需要改变你添加项目的方式。

在你的html中,它需要看起来像这样:

<figure itemscope="itemscope" itemtype="http://schema.org/Person">

特别注意,它需要是itemscope="itemscope",否则它将被剥离。

根据这个问题,这是有效的HTML5:HTML5有效的项目范围

你可以在这里找到更多关于白名单的信息:http://ugisozols.com/blog/2013/06/20/whitelisting-html-tags-and-attributes-in-refinery-cms-wymeditor/

如果你有很多标签,并且你想完全关闭验证,你可以将app/assets/javascripts/wymeditor/validators.js.erb复制到你的应用程序中,并注释掉大部分getValidTagAttributes函数,如下所示:

  getValidTagAttributes: function(tag, attributes)
  {
    var valid_attributes = {};
    var possible_attributes = this.getPossibleTagAttributes(tag);
    var regexp_attributes = [];
    $.each((possible_attributes || []), function(i, val) {
      if (val.indexOf("*") > -1) {
        regexp_attributes.push(new RegExp(val));
      }
    });
    var h = WYMeditor.Helper;
    for(var attribute in attributes) {
      var value = attributes[attribute];
    //if(!h.contains(this.skipped_attributes, attribute) && !h.contains(this.skipped_attribute_values, value)){
    //  if (typeof value != 'function') {
    //    if (h.contains(possible_attributes, attribute)) {
    //      if (this.doesAttributeNeedsValidation(tag, attribute)) {
    //        if(this.validateAttribute(tag, attribute, value)){
    //          valid_attributes[attribute] = value;
    //        }
    //      }else{
              valid_attributes[attribute] = value;
    //      }
    //    }
    //    else {
    //      $.each(regexp_attributes, function(i, val) {
    //        if (attribute.match(val)) {
    //          valid_attributes[attribute] = value;
    //        }
    //      });
    //    }
    //  }
    //}
    }
    return valid_attributes;
  },

请注意,像这样关闭所有标签的验证可能非常危险。

最新更新