Skip to content

Commit

Permalink
#131 Specify & test the dedent procedure for YAML-LD blocks
Browse files Browse the repository at this point in the history
  • Loading branch information
anatoly-scherbakov committed Feb 4, 2024
1 parent 6fabe8d commit 5c850ac
Show file tree
Hide file tree
Showing 6 changed files with 71 additions and 2 deletions.
15 changes: 15 additions & 0 deletions spec/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -1035,6 +1035,21 @@ <h2>Embedding YAML-LD in HTML Documents</h2>
-->
</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>
<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>
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>
File renamed without changes.
File renamed without changes.
22 changes: 20 additions & 2 deletions tests/manifest.jsonld
Original file line number Diff line number Diff line change
Expand Up @@ -195,8 +195,26 @@
"name": "YAML Stream with multiple documents embedded into HTML.",
"req": "must",
"option": {"extractAllScripts": true},
"input": "cases/html-and-yaml-streams/in.html",
"expect": "cases/html-and-yaml-streams/out.yamlld"
"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"
}
]
}

0 comments on commit 5c850ac

Please sign in to comment.