Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(closes #131) Embed YAML-LD into HTML <script> tag #132

Merged
merged 6 commits into from
Apr 3, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
node_modules
.idea
/web

web/
!web/.gitkeep
48 changes: 48 additions & 0 deletions spec/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -1007,6 +1007,54 @@ <h2>Interoperability Considerations</h2>
</p>
</section>

<section id="html">
<h2>Embedding YAML-LD in HTML Documents</h2>

<p>
YAML-LD content can be easily embedded in HTML [[HTML]] by placing it
in a <code>&lt;script></code> element with the type attribute set to
`application/ld+yaml`, as illustrated on an example below.
</p>

<pre class="example yaml"
data-transform="updateExample"
data-content-type="application/ld+yaml"
title="YAML-LD document embedded in HTML">
<!--
<script type="application/ld+yaml">
"@context": https://json-ld.org/contexts/person.jsonld
"@id": http://dbpedia.org/resource/John_Lennon
name: John Lennon
born: 1940-10-09
spouse: http://dbpedia.org/resource/Cynthia_Lennon
---
"@context": https://json-ld.org/contexts/person.jsonld
"@id": http://dbpedia.org/resource/Cynthia_Lennon
born: 1939-09-10
</script>
-->
</pre>

<p data-tests="manifest.html#html-dedent-needed,manifest.html#html-dedent-not-needed">
YAML syntax is indentation based. Before processing each `&lt;script>` block with YAML-LD content, YAML-LD processor MUST <em>dedent</em> the body of the block using the following procedure:
</p>

<ul>
<li>Count the number of <strong>leading spaces</strong> in the first line of the YAML-LD block, and save that to `dedent_count` variable,</li>
anatoly-scherbakov marked this conversation as resolved.
Show resolved Hide resolved
<li>
For each line of the YAML-LD block,
<ul>
<li>If the number of leading spaces is less than `dedent_count`, keep the line as-is,</li>
<li>Otherwise, remove exactly `dedent_count` leading spaces from the line.</li>
</ul>
</li>
</ul>

<p data-tests="manifest.html#html-and-yaml-streams">
If the YAML-LD <code>&lt;script></code> tag contains a <a>YAML Stream</a> with multiple <a>YAML documents</a>, each of these documents MUST be treated as if it was included in a separate <code>&lt;script></code> tag.
</p>
anatoly-scherbakov marked this conversation as resolved.
Show resolved Hide resolved
</section>

<section id="iana" class="appendix normative">
<h2>IANA Considerations</h2>

Expand Down
18 changes: 18 additions & 0 deletions tests/cases/html/dedent-needed.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<html>
<head>
<script type="application/ld+yaml">
"@context": https://json-ld.org/contexts/person.jsonld
"@id": http://dbpedia.org/resource/John_Lennon
name: John Lennon
born: 1940-10-09
spouse: http://dbpedia.org/resource/Cynthia_Lennon
---
"@context": https://json-ld.org/contexts/person.jsonld
"@id": http://dbpedia.org/resource/Cynthia_Lennon
born: 1939-09-10
</script>
</head>
<body>
<h1>Hi!</h1>
</body>
</html>
18 changes: 18 additions & 0 deletions tests/cases/html/dedent-not-needed.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<html>
<head>
<script type="application/ld+yaml">
"@context": https://json-ld.org/contexts/person.jsonld
"@id": http://dbpedia.org/resource/John_Lennon
name: John Lennon
born: 1940-10-09
spouse: http://dbpedia.org/resource/Cynthia_Lennon
---
"@context": https://json-ld.org/contexts/person.jsonld
"@id": http://dbpedia.org/resource/Cynthia_Lennon
born: 1939-09-10
</script>
</head>
<body>
<h1>Hi!</h1>
</body>
</html>
18 changes: 18 additions & 0 deletions tests/cases/html/stream.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<html>
<head>
<script type="application/ld+yaml">
"@context": https://json-ld.org/contexts/person.jsonld
"@id": http://dbpedia.org/resource/John_Lennon
name: John Lennon
born: 1940-10-09
spouse: http://dbpedia.org/resource/Cynthia_Lennon
---
"@context": https://json-ld.org/contexts/person.jsonld
"@id": http://dbpedia.org/resource/Cynthia_Lennon
born: 1939-09-10
</script>
</head>
<body>
<h1>Hi!</h1>
</body>
</html>
12 changes: 12 additions & 0 deletions tests/cases/html/stream.yamlld
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
- "@id": http://dbpedia.org/resource/John_Lennon
http://schema.org/birthDate:
- "@type": http://www.w3.org/2001/XMLSchema#date
"@value": 1940-10-09
http://xmlns.com/foaf/0.1/name:
- "@value": John Lennon
http://schema.org/spouse:
- "@id": http://dbpedia.org/resource/Cynthia_Lennon
- "@id": http://dbpedia.org/resource/Cynthia_Lennon
http://schema.org/birthDate:
- "@type": http://www.w3.org/2001/XMLSchema#date
"@value": 1939-09-10
27 changes: 27 additions & 0 deletions tests/manifest.jsonld
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,33 @@
"req": "must",
"input": "cases/cr-well-formed-3-negative-in.yamlld",
"expectErrorCode": "loading document failed"
},
{
"@id": "#html-and-yaml-streams",
"@type": ["jld:PositiveEvaluationTest", "jld:ExpandTest"],
"name": "YAML Stream with multiple documents embedded into HTML.",
"req": "must",
"option": {"extractAllScripts": true},
"input": "cases/html/stream.html",
"expect": "cases/html/stream.yamlld"
},
{
"@id": "#html-dedent-needed",
"@type": ["jld:PositiveEvaluationTest", "jld:ExpandTest"],
"name": "YAML Stream with multiple documents embedded into HTML.",
"req": "must",
"option": {"extractAllScripts": true},
"input": "cases/html/dedent-needed.html",
"expect": "cases/html/stream.yamlld"
},
{
"@id": "#html-dedent-not-needed",
"@type": ["jld:PositiveEvaluationTest", "jld:ExpandTest"],
"name": "YAML Stream with multiple documents embedded into HTML.",
"req": "must",
"option": {"extractAllScripts": true},
"input": "cases/html/dedent-not-needed.html",
"expect": "cases/html/stream.yamlld"
}
]
}
Empty file added web/.gitkeep
Empty file.
Loading