AMP:使用 AMP 提供的示例代码时,标记 'head > style[amp-boilerplate]' 内的强制性文本 (CDATA) 丢失或不正确

AMP: The mandatory text (CDATA) inside tag 'head > style[amp-boilerplate]' is missing or incorrect, when using AMP's provided sample code

我正在尝试使用 this tutorial and all sample code. However, when I go to validate my page, I'm seeing these two errors:

创建 AMP 页面

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

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

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

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

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

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

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

但是,文档指出代码中不允许 space。

Currently, allowed mutations are: (1) inserting arbitrary whitespace immediately after the style tag opens, and immediately before it closes; (2) replacing any space in the snippet below with arbitrary whitespace

来源:ampproject github

我刚刚 运行 进入这个,我的原因是 VS2015 试图对 GUI 布局有所帮助,但添加了空格和 return 行。粘贴示例代码并点击撤消 (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>