2

如果您熟悉 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>

有谁知道在炼油厂不删除它们的情况下保留模式的方法?

4

1 回答 1

0

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

这应该适用于您的图形标签:

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

请注意,如果您走这条路线,您将需要更改添加 itemope 的方式。

在您的 html 中,它需要如下所示:

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

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

根据这个问题,这是有效的 HTML5:HTML5 valid itemscope

您可以在此处找到有关白名单的更多信息: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;
  },

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

于 2015-07-29T22:04:33.770 回答