Inline Microdata content displays different from same markup in JSON-LD

余生颓废 提交于 2019-11-29 16:36:15

JSON-LD (as data block in a HTML script element) and Microdata work differently if the property value should be a string:

  • In JSON-LD the value is plain text (i.e., the characters < and > have no special meaning)
  • In Microdata the value is the textContent of the element (i.e., HTML elements get stripped)

In your JSON-LD example, there are not some tags stripped, it contains exactly the HTML tags (interpreted as plain text) which you provide in the text property.

Let’s say you have in your HTML <span><b>Hello world</b></span> and you want to provide the content "Hello world" as value for a text property.

In Microdata, you could use one of the following ways:

<span itemprop="text"><b>Hello world</b></span>
<span><b itemprop="text">Hello world</b></span>
<meta itemprop="text" content="Hello world" />

In JSON-LD, you can only use:

"text": "Hello world",

If you would use

"text": "<b>Hello world</b>",

the value would be "<b>Hello world</b>", where <b> and </b> are not HTML but part of the string value.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!