0

我正在将一个项目从 Umbraco 7 升级到 8。我注意到在 8 中,只有某些 html 标签会从宏 html 文件中呈现。例如,如果我在宏部分视图中使用以下 html:-

<div>
    <button>send</button>
    <input type='text' placeholder='some field' style='border: solid 1px #000' />
    <a href="https://www.google.com">some link</a>
</div>

在后台,DOM 中的 html 呈现如下:-

在此处输入图像描述

A 标签和 div 渲染良好,但按钮和输入被剥离。我尝试使用 HTML.Raw 无济于事。

当我发布内容时,它呈现得很好:- 在此处输入图像描述

有人在 Umbraco 8 中遇到过这个吗?

4

1 回答 1

0

原来 HTML 标签和属性正在被 Umbraco/lib/angular-sanitize/angular-sanitize.js 文件剥离。

您可以添加一组白名单变量来添加您的 html 标记和属性 - 然后后台将呈现它们。

    // Safe Block Elements - HTML5
      var blockElements = extend({}, optionalEndTagBlockElements, stringToMap('address,article,' +
              'aside,blockquote,caption,center,del,dir,div,dl,figure,figcaption,footer,h1,h2,h3,h4,h5,' +
              'h6,header,hgroup,hr,ins,map,menu,nav,ol,pre,section,table,ul,form')); //SG: added form

      // Inline Elements - HTML5
      var inlineElements = extend({}, optionalEndTagInlineElements, stringToMap('a,abbr,acronym,b,' +
              'bdi,bdo,big,br,cite,code,del,dfn,em,font,i,img,ins,kbd,label,map,mark,q,ruby,rp,rt,s,' +
            'samp,small,span,strike,strong,sub,sup,time,tt,u,var,input,button')); //SG: added input, button

  // Blocked Elements (will be stripped)
  var blockedElements = stringToMap('script'); //SG: Removed ,style

  var htmlAttrs = stringToMap('abbr,align,alt,axis,bgcolor,border,cellpadding,cellspacing,class,clear,' +
      'color,cols,colspan,compact,coords,dir,face,headers,height,hreflang,hspace,' +
      'ismap,lang,language,nohref,nowrap,rel,rev,rows,rowspan,rules,' +
      'scope,scrolling,shape,size,span,start,summary,tabindex,target,title,type,' +
        'valign,value,vspace,width,action,method,autocomplete,enctype,style'); //SG: Added action,method,autocomplete,enctype,style

您可以在此处阅读有关此 umbraco 8“功能”的更多信息 - https://www.stephengarside.co.uk/blog/webdev/umbraco-8-removing-html-tags-and-attributes-from-macros-in-back -办公室/

于 2019-11-13T07:18:59.560 回答