Skip to content

Commit 87ab2ee

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.
1 parent 9f2ef52 commit 87ab2ee

File tree

3 files changed

+111
-82
lines changed

3 files changed

+111
-82
lines changed
Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,28 @@
11
<table class="statements" data-result-for="Embedding JSON-LD in HTML with comments-expanded" data-to-rdf>
2-
<thead><tr>
2+
<thead><tr>
33
<th>Subject</th>
44
<th>Property</th>
55
<th>Value</th>
66
<th>Value Type</th>
77
</tr></thead>
8-
<tbody>
9-
<tr>
8+
<tbody>
9+
<tr>
1010
<td>http://dbpedia.org/resource/John_Lennon</td>
1111
<td>foaf:name</td>
1212
<td>John Lennon</td>
1313
<td> </td>
1414
</tr>
15-
<tr>
15+
<tr>
1616
<td>http://dbpedia.org/resource/John_Lennon</td>
1717
<td>schema:birthDate</td>
1818
<td>1940-10-09</td>
1919
<td>xsd:date</td>
2020
</tr>
21-
<tr>
21+
<tr>
2222
<td>http://dbpedia.org/resource/John_Lennon</td>
2323
<td>schema:spouse</td>
2424
<td>http://dbpedia.org/resource/Cynthia_Lennon</td>
2525
<td> </td>
2626
</tr>
27-
</tbody>
28-
</table>
27+
</tbody>
28+
</table>

index.html

Lines changed: 103 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -8401,80 +8401,6 @@ <h3>Graph Containers</h3>
84018401
</pre>
84028402
</aside>
84038403

8404-
<p>Depending on how the HTML document is served, certain strings may need
8405-
to be escaped. See
8406-
<a href="https://www.w3.org/TR/html52/semantics-scripting.html#restrictions-for-contents-of-script-elements">
8407-
Restrictions for contents of <code>script</code> elements
8408-
</a> in [[!HTML52]] for details. In particular, the content MAY be enclosed
8409-
in the HTML comment open (<code>&lt;!--</code>) and comment close (<code>--&gt;</code>) text sequences</p>
8410-
8411-
<aside class="example ds-selector-tabs"
8412-
title="Embedding JSON-LD in HTML with comments">
8413-
<div class="selectors">
8414-
<button class="selected" data-selects="original">Original</button>
8415-
<button data-selects="expanded">Expanded</button>
8416-
<button data-selects="statements">Statements</button>
8417-
<button data-selects="turtle">Turtle</button>
8418-
</div>
8419-
<pre class="original selected" data-transform="updateExample"
8420-
data-content-type="text/html">
8421-
<!--
8422-
<script type="application/ld+json">
8423-
< !--
8424-
{
8425-
"@context": "https://json-ld.org/contexts/person.jsonld",
8426-
"@id": "http://dbpedia.org/resource/John_Lennon",
8427-
"name": "John Lennon",
8428-
"born": "1940-10-09",
8429-
"spouse": "http://dbpedia.org/resource/Cynthia_Lennon"
8430-
}
8431-
-- >
8432-
</script>
8433-
-->
8434-
</pre>
8435-
<pre class="expanded"
8436-
data-transform="updateExample"
8437-
data-result-for="Embedding JSON-LD in HTML with comments-original">
8438-
<!--
8439-
[{
8440-
"@id": "http://dbpedia.org/resource/John_Lennon",
8441-
"http://xmlns.com/foaf/0.1/name": [{"@value": "John Lennon"}],
8442-
"http://schema.org/birthDate": [
8443-
{"@value": "1940-10-09", "@type": "http://www.w3.org/2001/XMLSchema#date"}
8444-
],
8445-
"http://schema.org/spouse": [
8446-
{"@id": "http://dbpedia.org/resource/Cynthia_Lennon"}
8447-
]
8448-
}]
8449-
-->
8450-
</pre>
8451-
<table class="statements"
8452-
data-result-for="Embedding JSON-LD in HTML with comments-expanded"
8453-
data-to-rdf>
8454-
<thead><tr><th>Subject</th><th>Property</th><th>Value</th><th>Value Type</th></tr></thead>
8455-
<tbody>
8456-
<tr><td>http://dbpedia.org/resource/John_Lennon</td><td>foaf:name</td><td>John Lennon</td><td>&nbsp;</td></tr>
8457-
<tr><td>http://dbpedia.org/resource/John_Lennon</td><td>schema:birthDate</td><td>1940-10-09</td><td>xsd:date</td></tr>
8458-
<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>
8459-
</tbody>
8460-
</table>
8461-
<pre class="turtle"
8462-
data-content-type="text/turtle"
8463-
data-transform="updateExample"
8464-
data-result-for="Embedding JSON-LD in HTML with comments-expanded"
8465-
data-to-rdf>
8466-
<!--
8467-
@prefix foaf: <http://xmlns.com/foaf/0.1/> .
8468-
@prefix schema: <http://schema.org/> .
8469-
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
8470-
8471-
<http://dbpedia.org/resource/John_Lennon> foaf:name "John Lennon";
8472-
schema:birthDate "1940-10-09"^^xsd:date;
8473-
schema:spouse <http://dbpedia.org/resource/Cynthia_Lennon> .
8474-
-->
8475-
</pre>
8476-
</aside>
8477-
84788404
<p>Defining how such data may be used is beyond the scope of this specification.
84798405
The embedded JSON-LD document might be extracted as is or, e.g., be
84808406
interpreted as RDF.</p>
@@ -8564,6 +8490,109 @@ <h3>Graph Containers</h3>
85648490
containing HTML document is used to establish the default <a>base IRI</a> of the enclosed
85658491
JSON-LD content.</p>
85668492

8493+
<section><h3>Restrictions for contents of JSON-LD <code>script</code> elements</h3>
8494+
8495+
<p>Depending on how the HTML document is served, certain strings may need
8496+
to be escaped. In particular, the content MAY be enclosed
8497+
in the HTML <em>comment-open</em> (<code>&lt;!--</code>) and <em>comment-close</em> (<code>--&gt;</code>) text sequences.</p>
8498+
<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>
8499+
the <a data-cite="DOM#dom-node-textcontent">textContent</a> of a script element may include balanced comments
8500+
and other text which complicate extracting the JSON-LD content from a <a data-cite="HTML52/semantics-scripting.html#data-block">data blocks</a>.
8501+
JSON-LD places further restrictions on the contents of
8502+
<a data-cite="HTML52/semantics-scripting.html#the-script-element">script elements</a> containing JSON-LD.</p>
8503+
<p>A JSON-LD script element MAY begin with an optional <em>comment-open</em> surrounded by any amount of white space,
8504+
followed by valid JSON and ending with an optional <em>comment-close</em> surrounded by any amount of white space.
8505+
Any content within the JSON content which can be confused with a <em>comment-open</em>, <em>script-open</em>,
8506+
<em>comment-close</em>, or <em>script-close</em> MUST be escaped using a REVERSE SOLIDUS (<code>\</code>) character
8507+
as follows:</p>
8508+
<ul>
8509+
<li><code>&lt;!--</code><code>&lt;\!--</code></li>
8510+
<li><code>&lt;script</code><code>&lt;\script</code></li>
8511+
<li><code>--&gt;</code><code>--\&gt;</code></li>
8512+
<li><code>&lt;/script</code><code>&lt;\/script</code></li>
8513+
</ul>
8514+
<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>
8515+
<ul>
8516+
<li><code>&amp;amp;</code> → &amp; (<a href="/wiki/Ampersand" title="Ampersand">ampersand</a>, U+0026)</li>
8517+
<li><code>&amp;lt;</code> → &lt; (less-than sign, U+003C)</li>
8518+
<li><code>&amp;gt;</code> → &gt; (greater-than sign, U+003E)</li>
8519+
<li><code>&amp;quot;</code> → " (quotation mark, U+0022)</li>
8520+
<li><code>&amp;apos;</code> → ' (apostrophe, U+0027)</li>
8521+
</ul>
8522+
<p>JSON-LD Processors MUST remove surrounding <em>comment-open</em> and <em>comment-close</em>
8523+
sequences, unescape any escaped <em>comment-open</em>, <em>comment-close</em>,
8524+
<em>script-open</em>, and <em>script-close</em> sequences,
8525+
and turn <a data-cite="HTML5/syntax.html#character-references">HTML Character references</a> into the corresponding Unicode.
8526+
</p>
8527+
8528+
<aside class="example ds-selector-tabs"
8529+
title="Embedding JSON-LD in HTML with comments">
8530+
<div class="selectors">
8531+
<button class="selected" data-selects="original">Original</button>
8532+
<button data-selects="expanded">Expanded</button>
8533+
<button data-selects="statements">Statements</button>
8534+
<button data-selects="turtle">Turtle</button>
8535+
</div>
8536+
<pre class="original selected" data-transform="updateExample"
8537+
data-content-type="text/html">
8538+
<!--
8539+
<script type="application/ld+json">
8540+
< !--
8541+
{
8542+
"@context": "https://json-ld.org/contexts/person.jsonld",
8543+
"@id": "http://dbpedia.org/resource/John_Lennon",
8544+
"name": "John Lennon",
8545+
"born": "1940-10-09",
8546+
"spouse": "http://dbpedia.org/resource/Cynthia_Lennon"
8547+
}
8548+
-- >
8549+
</script>
8550+
-->
8551+
</pre>
8552+
<pre class="expanded"
8553+
data-transform="updateExample"
8554+
data-result-for="Embedding JSON-LD in HTML with comments-original">
8555+
<!--
8556+
[{
8557+
"@id": "http://dbpedia.org/resource/John_Lennon",
8558+
"http://xmlns.com/foaf/0.1/name": [{"@value": "John Lennon"}],
8559+
"http://schema.org/birthDate": [
8560+
{"@value": "1940-10-09", "@type": "http://www.w3.org/2001/XMLSchema#date"}
8561+
],
8562+
"http://schema.org/spouse": [
8563+
{"@id": "http://dbpedia.org/resource/Cynthia_Lennon"}
8564+
]
8565+
}]
8566+
-->
8567+
</pre>
8568+
<table class="statements"
8569+
data-result-for="Embedding JSON-LD in HTML with comments-expanded"
8570+
data-to-rdf>
8571+
<thead><tr><th>Subject</th><th>Property</th><th>Value</th><th>Value Type</th></tr></thead>
8572+
<tbody>
8573+
<tr><td>http://dbpedia.org/resource/John_Lennon</td><td>foaf:name</td><td>John Lennon</td><td>&nbsp;</td></tr>
8574+
<tr><td>http://dbpedia.org/resource/John_Lennon</td><td>schema:birthDate</td><td>1940-10-09</td><td>xsd:date</td></tr>
8575+
<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>
8576+
</tbody>
8577+
</table>
8578+
<pre class="turtle"
8579+
data-content-type="text/turtle"
8580+
data-transform="updateExample"
8581+
data-result-for="Embedding JSON-LD in HTML with comments-expanded"
8582+
data-to-rdf>
8583+
<!--
8584+
@prefix foaf: <http://xmlns.com/foaf/0.1/> .
8585+
@prefix schema: <http://schema.org/> .
8586+
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
8587+
8588+
<http://dbpedia.org/resource/John_Lennon> foaf:name "John Lennon";
8589+
schema:birthDate "1940-10-09"^^xsd:date;
8590+
schema:spouse <http://dbpedia.org/resource/Cynthia_Lennon> .
8591+
-->
8592+
</pre>
8593+
</aside>
8594+
</section>
8595+
85678596
<section><h3>Locating a Specific JSON-LD Script Element</h3>
85688597
<p>A specific
85698598
<a data-cite="HTML52/semantics-scripting.html#the-script-element">script element</a>

yaml/Embedding-JSON-LD-in-HTML-with-comments-expanded.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Example 102: Embedding JSON-LD in HTML with comments-expanded
1+
Example 103: Embedding JSON-LD in HTML with comments-expanded
22
---
33
- "@id": http://dbpedia.org/resource/John_Lennon
44
http://xmlns.com/foaf/0.1/name:

0 commit comments

Comments
 (0)