Skip to content

Commit cf9030b

Browse files
committed
Add section on restrictions for JSON-LD script elements, which is more restrictive than the base HTML definitions. This includes a sketch processing model for removing comments and unescaping the resulting content.
(cherry picked from commit 87ab2ee)
1 parent 472285a commit cf9030b

File tree

1 file changed

+104
-0
lines changed

1 file changed

+104
-0
lines changed

index.html

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8592,6 +8592,110 @@ <h3>Graph Containers</h3>
85928592
</aside>
85938593
</section>
85948594

8595+
<section><h3>Restrictions for contents of JSON-LD <code>script</code> elements</h3>
8596+
8597+
<p>Depending on how the HTML document is served, certain strings may need
8598+
to be escaped. In particular, the content MAY be enclosed
8599+
in the HTML <em>comment-open</em> (<code>&lt;!--</code>) and <em>comment-close</em> (<code>--&gt;</code>) text sequences.</p>
8600+
<p>As described in HTML <a data-cite="HTML52/semantics-scripting.html#restrictions-for-contents-of-script-elements">Restrictions for contents of <code>&lt;script&gt;</code> elements</a>
8601+
the <a data-cite="DOM#dom-node-textcontent">textContent</a> of a script element may include balanced comments
8602+
and other text which complicate extracting the JSON-LD content from a <a data-cite="HTML52/semantics-scripting.html#data-block">data blocks</a>.
8603+
JSON-LD places further restrictions on the contents of
8604+
<a data-cite="HTML52/semantics-scripting.html#the-script-element">script elements</a> containing JSON-LD.</p>
8605+
<p>A JSON-LD script element MAY begin with an optional <em>comment-open</em> surrounded by any amount of white space,
8606+
followed by valid JSON and ending with an optional <em>comment-close</em> surrounded by any amount of white space.
8607+
Any content within the JSON content which can be confused with a <em>comment-open</em>, <em>script-open</em>,
8608+
<em>comment-close</em>, or <em>script-close</em> MUST be escaped using a REVERSE SOLIDUS (<code>\</code>) character
8609+
as follows:</p>
8610+
<ul>
8611+
<li><code>&lt;!--</code><code>&lt;\!--</code></li>
8612+
<li><code>&lt;script</code><code>&lt;\script</code></li>
8613+
<li><code>--&gt;</code><code>--\&gt;</code></li>
8614+
<li><code>&lt;/script</code><code>&lt;\/script</code></li>
8615+
</ul>
8616+
<p>Additionally, content of a script element MAY be escaped using <a data-cite="HTML5/syntax.html#character-references">HTML Character references</a>, such as the following:</p>
8617+
<ul>
8618+
<li><code>&amp;amp;</code> → &amp; (<a href="/wiki/Ampersand" title="Ampersand">ampersand</a>, U+0026)</li>
8619+
<li><code>&amp;lt;</code> → &lt; (less-than sign, U+003C)</li>
8620+
<li><code>&amp;gt;</code> → &gt; (greater-than sign, U+003E)</li>
8621+
<li><code>&amp;quot;</code> → " (quotation mark, U+0022)</li>
8622+
<li><code>&amp;apos;</code> → ' (apostrophe, U+0027)</li>
8623+
</ul>
8624+
<p>JSON-LD Processors MUST remove surrounding <em>comment-open</em> and <em>comment-close</em>
8625+
sequences, unescape any escaped <em>comment-open</em>, <em>comment-close</em>,
8626+
<em>script-open</em>, and <em>script-close</em> sequences,
8627+
and turn <a data-cite="HTML5/syntax.html#character-references">HTML Character references</a> into the corresponding Unicode.
8628+
</p>
8629+
8630+
<aside class="example ds-selector-tabs"
8631+
title="Embedding JSON-LD in HTML with comments">
8632+
<div class="selectors">
8633+
<button class="selected" data-selects="original">Original</button>
8634+
<button data-selects="expanded">Expanded</button>
8635+
<button data-selects="statements">Statements</button>
8636+
<button data-selects="turtle">Turtle</button>
8637+
</div>
8638+
<pre class="original selected" data-transform="updateExample"
8639+
data-content-type="text/html">
8640+
<!--
8641+
<script type="application/ld+json">
8642+
< !--
8643+
{
8644+
"@context": "https://json-ld.org/contexts/person.jsonld",
8645+
"@id": "http://dbpedia.org/resource/John_Lennon",
8646+
"name": "John Lennon",
8647+
"born": "1940-10-09",
8648+
"spouse": "http://dbpedia.org/resource/Cynthia_Lennon"
8649+
}
8650+
-- >
8651+
</script>
8652+
-->
8653+
</pre>
8654+
<pre class="expanded"
8655+
data-transform="updateExample"
8656+
data-result-for="Embedding JSON-LD in HTML with comments-original">
8657+
<!--
8658+
[{
8659+
"@id": "http://dbpedia.org/resource/John_Lennon",
8660+
"http://xmlns.com/foaf/0.1/name": [{"@value": "John Lennon"}],
8661+
"http://schema.org/birthDate": [
8662+
{"@value": "1940-10-09", "@type": "http://www.w3.org/2001/XMLSchema#date"}
8663+
],
8664+
"http://schema.org/spouse": [
8665+
{"@id": "http://dbpedia.org/resource/Cynthia_Lennon"}
8666+
]
8667+
}]
8668+
-->
8669+
</pre>
8670+
<table class="statements"
8671+
data-result-for="Embedding JSON-LD in HTML with comments-expanded"
8672+
data-to-rdf>
8673+
<thead><tr><th>Subject</th><th>Property</th><th>Value</th><th>Value Type</th></tr></thead>
8674+
<tbody>
8675+
<tr><td>http://dbpedia.org/resource/John_Lennon</td><td>foaf:name</td><td>John Lennon</td><td>&nbsp;</td></tr>
8676+
<tr><td>http://dbpedia.org/resource/John_Lennon</td><td>schema:birthDate</td><td>1940-10-09</td><td>xsd:date</td></tr>
8677+
<tr><td>http://dbpedia.org/resource/John_Lennon</td><td>schema:spouse</td><td>http://dbpedia.org/resource/Cynthia_Lennon</td><td>&nbsp;</td></tr>
8678+
</tbody>
8679+
</table>
8680+
<pre class="turtle"
8681+
data-content-type="text/turtle"
8682+
data-transform="updateExample"
8683+
data-result-for="Embedding JSON-LD in HTML with comments-expanded"
8684+
data-to-rdf>
8685+
<!--
8686+
@prefix foaf: <http://xmlns.com/foaf/0.1/> .
8687+
@prefix schema: <http://schema.org/> .
8688+
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
8689+
8690+
<http://dbpedia.org/resource/John_Lennon> foaf:name "John Lennon";
8691+
schema:birthDate "1940-10-09"^^xsd:date;
8692+
schema:spouse <http://dbpedia.org/resource/Cynthia_Lennon> .
8693+
-->
8694+
</pre>
8695+
</aside>
8696+
</section>
8697+
>>>>>>> 87ab2ee... Add section on restrictions for JSON-LD script elements, which is more restrictive than the base HTML definitions. This includes a sketch processing model for removing comments and unescaping the resulting content.
8698+
85958699
<section><h3>Locating a Specific JSON-LD Script Element</h3>
85968700
<p>A specific
85978701
<a data-cite="HTML52/semantics-scripting.html#the-script-element">script element</a>

0 commit comments

Comments
 (0)