【问题标题】:AMP: The mandatory text (CDATA) inside tag 'head > style[amp-boilerplate]' is missing or incorrect, when using AMP's provided sample codeAMP:使用 AMP 提供的示例代码时,标签“head > style[amp-boilerplate]”内的强制文本 (CDATA) 缺失或不正确
【发布时间】:2016-08-16 13:59:09
【问题描述】:

我正在尝试使用 this tutorial 和所有示例代码创建一个 AMP 页面。但是,当我去验证我的页面时,我看到了这两个错误:

我为此所做的每一次搜索都告诉我需要使用本教程中已经提供的确切字符串:https://github.com/ampproject/amphtml/blob/master/spec/amp-boilerplate.md

我的示例代码在这里:http://pastebin.com/VZ1UEs1q

我做错了什么?我唯一能想到的是,我的 Visual Studio 正在自动扩展和格式化 <style><noscript> 标记的 1-liner。

【问题讨论】:

    标签: html amp-html


    【解决方案1】:

    在此处编写链接教程的 AMP 团队成员 –

    我认为你的假设是正确的。转到https://validator.ampproject.org/ 并尝试仅更改<style amp-boilerplate> 内容中的一个字符,您将看到与您看到的相同的错误。

    样板代码必须完全匹配——也就是说,没有添加换行符、格式等任何内容。我可以看到这可能是令人沮丧的根源,但是在验证器中进行更宽容的检查会更加昂贵(我们必须实际解析 CSS,而不是仅仅匹配字符串)。

    【讨论】:

    • 谢谢,这就是给我的!我未格式化代码,它工作正常!自从您编写了本教程以来,这只是一个建议,在页面上放置一个警告可能是个好主意。
    【解决方案2】:

    我刚刚遇到这个问题,我的原因是 VS2015 试图对 GUI 布局有所帮助,但添加了空格和返回行。粘贴示例代码并点击撤消(Ctrl + Z)后,问题就消失了。

    对我有用的最终结果是确保将模板样式缩小为一行。

    <style amp-boilerplate>body{-webkit-animation:-amp-start 8s steps(1,end) 0s 1 normal both;-moz-animation:-amp-start 8s steps(1,end) 0s 1 normal both;-ms-animation:-amp-start 8s steps(1,end) 0s 1 normal both;animation:-amp-start 8s steps(1,end) 0s 1 normal both}@-webkit-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@-moz-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@-ms-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@-o-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}</style>
        <noscript><style amp-boilerplate>body{-webkit-animation:none;-moz-animation:none;-ms-animation:none;animation:none}</style></noscript>
    

    【讨论】:

    • 没错!它的意思是单行写!你的答案是正确的!
    【解决方案3】:

    当我尝试在同一个地方插入自己的样式时遇到了同样的问题,但结果发现它需要放在&lt;style amp-custom&gt; 中。

    但是,文档指出代码中不允许有空格。

    目前,允许的突变是:(1)在样式标签打开后立即插入任意空格,并在其关闭前立即插入; (2) 用任意空格替换下面sn-p中的任何空格

    来源:ampproject github

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-01-16
      • 1970-01-01
      • 2023-04-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-07-30
      • 1970-01-01
      相关资源
      最近更新 更多