Schema.org 标记中的 "description" 是否必须不含 HTML 标签?
Does "description" in Schema.org markup have to be free of HTML tags?
我发现所有Product
Schema.org微数据的电子商务网站都在description
属性中使用纯文本。
是否有一些规范明确禁止使用某些文本格式标签进行标记,例如:
<div itemscope itemtype="http://schema.org/Product">
<meta itemprop="name" content="Name" />
<meta itemprop="description" content="<p>First paragraph with <b>bold words<b/>.</p><p>Second paragraph.</p>" />
</div>
description
的数据类型定义为 Text
。我认为很明显的意图是这应该是纯文本。
如果描述最终出现在网页上,例如在搜索引擎结果中,文本无疑会被 HTML 编码以防止脚本注入之类的事情,因此实际上会显示给用户使用尖括号而不是格式。
您正在使用 meta
element. Its content
attribute can only contain a string. If you’d provide a value like <b>bold</b>
, <b>
and </b>
would be part of the value, and these would be interpreted as text,而不是标记。
对于Schema.org的description
属性,你当然可以使用不同的元素(比如p
)。这可能包含标记,但 description
属性 的值将是 the text value.
所以
<p itemprop="description">foo <b>bar</b></p>
值为 "foo bar"。
Matthew is right, you should only provide text as value to description
meta tag. But Unor 也对,这种情况下推荐的方法是将微数据用于标记本身,例如:
<div itemscope itemtype="http://schema.org/Product">
<p itemprop="name">Product's Name</p>
<p itemprop="description">Products description.<strong>Some bold text</strong></p>
Here you can see exactly as Google recommends it. And here 您可以逐页测试,甚至可以将您的代码粘贴到此处以仅测试一个块。
您可能想阅读 here 为什么要避免使用 <b>
作为粗体。
如果您对模式数据使用较新的 JSON-LD 格式,那么似乎(至少对于 Google)可以为某些字段包含 HTML 标记 -事实上,他们实际上要求它。请参阅他们对 JobPostings 的建议,例如,他们在说明中说明:
The full description of the job in HTML format.
You must format the description in HTML.
他们的 Structured Data Testing Tool 似乎肯定不会在字段中抱怨 HTML,尽管您可能希望将其限制为基本标签。很难说其他解析器是否可以。
虽然这是一个老问题。我有一个不同的解决方案。
该描述包含标签以外的标签,因此 google 未将其读取为文本。
你可以在内容中传递描述属性,像这样。
<p itemprop="description" content="<%:Model.Description %>"><%:Html.Raw(Model.Description) %> </p>
也许应该在发布之前清理文本。该工具似乎可以使用它,所以对我来说似乎没问题。
我发现所有Product
Schema.org微数据的电子商务网站都在description
属性中使用纯文本。
是否有一些规范明确禁止使用某些文本格式标签进行标记,例如:
<div itemscope itemtype="http://schema.org/Product">
<meta itemprop="name" content="Name" />
<meta itemprop="description" content="<p>First paragraph with <b>bold words<b/>.</p><p>Second paragraph.</p>" />
</div>
description
的数据类型定义为 Text
。我认为很明显的意图是这应该是纯文本。
如果描述最终出现在网页上,例如在搜索引擎结果中,文本无疑会被 HTML 编码以防止脚本注入之类的事情,因此实际上会显示给用户使用尖括号而不是格式。
您正在使用 meta
element. Its content
attribute can only contain a string. If you’d provide a value like <b>bold</b>
, <b>
and </b>
would be part of the value, and these would be interpreted as text,而不是标记。
对于Schema.org的description
属性,你当然可以使用不同的元素(比如p
)。这可能包含标记,但 description
属性 的值将是 the text value.
所以
<p itemprop="description">foo <b>bar</b></p>
值为 "foo bar"。
Matthew is right, you should only provide text as value to description
meta tag. But Unor 也对,这种情况下推荐的方法是将微数据用于标记本身,例如:
<div itemscope itemtype="http://schema.org/Product">
<p itemprop="name">Product's Name</p>
<p itemprop="description">Products description.<strong>Some bold text</strong></p>
Here you can see exactly as Google recommends it. And here 您可以逐页测试,甚至可以将您的代码粘贴到此处以仅测试一个块。
您可能想阅读 here 为什么要避免使用 <b>
作为粗体。
如果您对模式数据使用较新的 JSON-LD 格式,那么似乎(至少对于 Google)可以为某些字段包含 HTML 标记 -事实上,他们实际上要求它。请参阅他们对 JobPostings 的建议,例如,他们在说明中说明:
The full description of the job in HTML format.
You must format the description in HTML.
他们的 Structured Data Testing Tool 似乎肯定不会在字段中抱怨 HTML,尽管您可能希望将其限制为基本标签。很难说其他解析器是否可以。
虽然这是一个老问题。我有一个不同的解决方案。 该描述包含标签以外的标签,因此 google 未将其读取为文本。
你可以在内容中传递描述属性,像这样。
<p itemprop="description" content="<%:Model.Description %>"><%:Html.Raw(Model.Description) %> </p>
也许应该在发布之前清理文本。该工具似乎可以使用它,所以对我来说似乎没问题。