简体   繁体   English

Schema.org 标记中的“描述”是否必须不含 HTML 标签?

[英]Does "description" in Schema.org markup have to be free of HTML tags?

All e-commerce websites with Product Schema.org Microdata that I found use plain text in description property.我发现所有带有Product Schema.org Microdata 的电子商务网站都在description属性中使用纯文本。

Is there some specification that clearly prohibits markup with some text formatting tags like:是否有一些规范明确禁止使用某些文本格式标签进行标记,例如:

<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>

If you are using the newer JSON-LD format for schema data then it seems (at least with Google) that it's OK to include HTML markup for some fields - indeed, they actually ask for it.如果您对架构数据使用较新的 JSON-LD 格式,那么似乎(至少对于 Google)可以为某些字段包含 HTML 标记 - 事实上,他们实际上要求这样做。 See their recommendation for JobPostings , for example, where they state for description:例如,请参阅他们对JobPostings的建议,他们在其中说明:

The full description of the job in HTML format. HTML 格式的完整职位描述。

You must format the description in HTML.您必须在 HTML 中格式化描述。

Their Structured Data Testing Tool certainly doesn't seem to complain about HTML in fields, though you probably want to limit it to basic tags.他们的结构化数据测试工具似乎不会抱怨字段中的 HTML,尽管您可能希望将其限制为基本标签。 Whether other parsers are OK with it is difficult to say.其他解析器是否可以使用很难说。

You are using the meta element .您正在使用meta元素 Its content attribute can only contain a string.它的content属性只能包含一个字符串。 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 , not as markup.如果您提供像<b>bold</b>这样的值, <b></b>将成为该值的一部分,并且这些将被解释为 text ,而不是标记。

For Schema.org's description property, you can of course use a different element (like p ).对于 Schema.org 的description属性,您当然可以使用不同的元素(如p )。 This may contain markup, but the value for the description property will be the text value .这可能包含标记,但description属性的值将是文本值

So for因此对于

<p itemprop="description">foo <b>bar</b></p>

the value would be "foo bar".该值将是“foo bar”。

The datatype of description is defined as Text . description的数据类型定义为Text I think it's clear that the intention is that this should be plain text.我认为很明显,其意图是这应该是纯文本。

In cases where the description ends up on a web page, such as in search engine results, the text will doubtless be HTML-encoded to prevent things like script injection, so will actually be displayed to the user with the angle brackets instead of as formatting.在描述最终出现在网页上的情况下,例如在搜索引擎结果中,文本无疑将被 HTML 编码以防止诸如脚本注入之类的事情,因此实际上将使用尖括号而不是格式显示给用户.

Matthew is right, you should only provide text as value to description meta tag. 马修是对的,您应该只提供文本作为description元标记的值。 But Unor is also right, the recommended method in this case is using microdata to the markup itself, like:但是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. 在这里,您可以完全按照 Google 推荐的方式查看。 And here you can test page by page or even paste your code there to test just a block. 在这里,您可以逐页测试,甚至可以将代码粘贴到那里来测试一个块。

You might want to read here why should you avoid using <b> for bold.您可能想在这里阅读为什么要避免使用<b>表示粗体。

Though this is an old question.虽然这是一个老问题。 I have a different solution.我有一个不同的解决方案。 The description had tags other than the tags so it was not read as text by google.描述有标签以外的标签,所以它不会被谷歌读取为文本。

You can pass the description in the content property , like so.您可以像这样在 content 属性中传递描述。

  <p itemprop="description" content="<%:Model.Description %>"><%:Html.Raw(Model.Description) %> </p>

Perhaps the text should be cleaned before posting it.也许应该在发布之前清理文本。 The tool seems to use it so seems ok to me.该工具似乎使用它,所以对我来说似乎没问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM