diff --git a/common/common.js b/common/common.js index b9e93ab1..14be9d70 100644 --- a/common/common.js +++ b/common/common.js @@ -271,6 +271,6 @@ function unComment(doc, content) { return content .replace(//, '') - .replace(/< !--/g, ''); + .replace(/< !\s*-\s*-/g, ''); } diff --git a/common/extract-examples.rb b/common/extract-examples.rb index 89fb6edb..5035f657 100755 --- a/common/extract-examples.rb +++ b/common/extract-examples.rb @@ -319,13 +319,18 @@ def save_example(examples:, element:, title:, example_number:, error:, warn:) $stdout.write "F".colorize(:red) next end + + # Get base from document, if present + html_base = doc.at_xpath('/html/head/base/@href') + ex[:base] = html_base.to_s if html_base + script_content = doc.at_xpath(xpath) if script_content # Remove (faked) XML comments and unescape sequences content = script_content .inner_html - .sub(/^\s*< !--/, '') - .sub(/-- >\s*$/, '') + .sub(/^\s*< !\s*-\s*-/, '') + .sub(/-\s*- >\s*$/, '') .gsub(/</, '<') end @@ -438,7 +443,15 @@ def save_example(examples:, element:, title:, example_number:, error:, warn:) # Set argument to referenced content to be parsed args[0] = if examples[ex[:result_for]][:ext] == 'html' && method == :expand # If we are expanding, and the reference is HTML, find the first script element. - doc = Nokogiri::HTML.parse(examples[ex[:result_for]][:content]) + doc = Nokogiri::HTML.parse( + examples[ex[:result_for]][:content] + .sub(/^\s*< !\s*-\s*-/, '') + .sub(/-\s*- >\s*$/, '')) + + # Get base from document, if present + html_base = doc.at_xpath('/html/head/base/@href') + options[:base] = html_base.to_s if html_base + script_content = doc.at_xpath(xpath) unless script_content errors << "Example #{ex[:number]} at line #{ex[:line]} references example #{ex[:result_for].inspect} with no JSON-LD script element" @@ -447,12 +460,13 @@ def save_example(examples:, element:, title:, example_number:, error:, warn:) end StringIO.new(script_content .inner_html - .sub(/^\s*< !--/, '') - .sub(/-- >\s*$/, '') .gsub(/</, '<')) elsif examples[ex[:result_for]][:ext] == 'html' && ex[:target] # Only use the targeted script - doc = Nokogiri::HTML.parse(examples[ex[:result_for]][:content]) + doc = Nokogiri::HTML.parse( + examples[ex[:result_for]][:content] + .sub(/^\s*< !\s*-\s*-/, '') + .sub(/-\s*- >\s*$/, '')) script_content = doc.at_xpath(xpath) unless script_content errors << "Example #{ex[:number]} at line #{ex[:line]} references example #{ex[:result_for].inspect} with no JSON-LD script element" @@ -461,8 +475,6 @@ def save_example(examples:, element:, title:, example_number:, error:, warn:) end StringIO.new(script_content .to_html - .sub(/^\s*< !--/, '') - .sub(/-- >\s*$/, '') .gsub(/</, '<')) else StringIO.new(examples[ex[:result_for]][:content]) diff --git a/index.html b/index.html index 06f7a35d..8d0d8064 100644 --- a/index.html +++ b/index.html @@ -4658,6 +4658,64 @@

Data Round Tripping

+
+

HTML Content Algorithms

+
+

Extract Script Content Algorithm

+ +

The algorithm extracts the text content a + JSON-LD script element into a dictionary or array of dictionaries. + A JSON-LD script element is a script element + within an HTML [[HTML52]] document with the with the type attribute set to + application/ld+json.

+ +
+

Overview

+

As a data block + may be inside a comment, and may be escaped, the algorithm extracts the JSON from any comment, + removes REVERSE SOLIDUS escapes, + and reverses HTML Character references. +

+ +
+

Algorithm

+

The algorithm takes a single required input variable: source, + the textContent of an HTML script element.

+

For the purpose of this algorithm, the following tokens are defined in [[ABNF]]:

+ +
+  space-character = %20 ; SPACE
+                  / %09 ; CHARACTER TABULATION (tab)
+                  / %0A ; LINE FEED (LF)
+                  / %0C ; FORM FEED (FF)
+                  / %0D ; CARRIAGE RETURN (CR)
+  comment-open    = *space-character "<!--" *space-character
+  comment-close   = *space-character "-->" *space-character
+      
+ +
    +
  1. If source begins with comment-open and ends with comment-close, + remove those sequences from source.
  2. +
  3. If source contains comment-open or comment-close, + an invalid script element has been detected, and processing is aborted.
  4. +
  5. For all occurances of the any of the character sequences + <\script, + <\/script, + <\!--, + or --\> + in source using a case-insenstive match, + replace the sequence with the equivalent sequence excluding the REVERSE SOLIDUS (\).
  6. +
  7. For all occurances of a HTML Character reference in source, + replace the sequence with the equivalent Unicode character as defined + in Named character references in [[HTML52]].
  8. +
  9. If source is not a valid JSON document, + an invalid script element has been detected, and processing is aborted.
  10. +
  11. Return the result of transforming source into the internal representation.
  12. +
+
+
+
+

The Application Programming Interface

@@ -4716,199 +4774,231 @@

The JsonLdProcessor Interface

compact
-

Compacts the given input using the - context according to the steps in the - Compaction algorithm:

+

Compacts the given input using the + context according to the steps in the Compaction algorithm:

    -
  1. Create a new Promise promise and return it. The - following steps are then executed asynchronously.
  2. -
  3. Set expanded input to the result of using the - expand - method using input and options, - with ordered set to false. -
  4. If context is a dictionary having an @context member, set - context to that member's value, otherwise to context.
  5. +
  6. Create a new Promise promise and return it. + The following steps are then executed asynchronously.
  7. +
  8. Set expanded input to the result of + using the expand method + using input + and options, + with ordered set to false, + and extractAllScripts defaulting to false. +
  9. If context is a dictionary having an @context member, + set context to that member's value, + otherwise to context.
  10. Initialize an active context using context; - the base IRI is set to - the base option from - options, if set; - otherwise, if the - compactToRelative option is - true, to the IRI of the currently being processed - document, if available; otherwise to null.
  11. -
  12. Set compacted output to the result of using the - Compaction algorithm, using active context, + the base IRI is set to the base option from options, if set; + otherwise, if the compactToRelative option is true, + to the IRI of the currently being processed document, if available; + otherwise to null.
  13. +
  14. Set compacted output to the result of using the Compaction algorithm, + using active context, an empty dictionary as inverse context, null as property, - expanded input as element, and if passed, the - compactArrays + expanded input as element, + and if passed, the compactArrays and ordered flags in options.
  15. -
  16. Fulfill the promise passing compacted output. +
  17. Fulfill the promise passing compacted output transforming compacted output from the internal representation to a JSON serialization.
input
-
The dictionary, array of dictionaries to perform the compaction upon or an - IRI referencing the JSON-LD document to compact.
+
The dictionary, + array of dictionaries to perform the compaction upon, + or an IRI referencing the JSON-LD document to compact.
context
-
The context to use when compacting the input; - it can be specified by using a dictionary, an - IRI, or an array consisting of - dictionaries and IRIs.
+
The context to use when compacting the input; + it can be specified by using a dictionary, + an IRI, + or an array consisting of dictionaries and IRIs.
options
-
A set of options to configure the algorithms. This allows, e.g., - to set the input document's base IRI.
+
A set of options to configure the algorithms. + This allows, e.g., to set the input document's base IRI.
expand
-

Expands the given input according to - the steps in the Expansion algorithm:

+

Expands the given input + according to the steps in the Expansion algorithm:

    -
  1. Create a new Promise promise and return it. The - following steps are then executed asynchronously.
  2. -
  3. If the passed input is a string - representing the IRI of a remote document, dereference it. - If the retrieved document's content type is neither application/json, - nor application/ld+json, nor any other media type using a - +json suffix as defined in [[RFC6839]], reject the promise passing an - loading document failed - error.
  4. -
  5. Initialize a new empty active context. The base IRI - of the active context is set to the IRI of the currently being processed - document, if available; otherwise to null. If set, the - base option from options overrides the base IRI.
  6. -
  7. If an - expandContext option - has been passed, update the active context using the - Context Processing algorithm, passing the - expandContext - as local context. If - expandContext - is a dictionary having an @context member, pass that member's value instead.
  8. -
  9. Once input has been retrieved, the response has an HTTP Link Header [[RFC8288]] - using the http://www.w3.org/ns/json-ld#context link relation - and a content type of application/json or any media type - with a +json suffix as defined in [[RFC6839]] except - application/ld+json, update the active context using the - Context Processing algorithm, passing the - context referenced in the HTTP Link Header as local context. The - HTTP Link Header is ignored for documents served as application/ld+json If - multiple HTTP Link Headers using the http://www.w3.org/ns/json-ld#context - link relation are found, the promise is rejected with a JsonLdError whose code is set to - multiple context link headers +
  10. Create a new Promise promise and return it. + The following steps are then executed asynchronously.
  11. +
  12. If the passed input + is a string representing the IRI of a remote document, dereference it as original input. + If the retrieved document's Content-Type is neither + text/html, + application/json, + application/ld+json, + nor any other media type using a + +json suffix as defined in [[RFC6839]], + reject the promise passing an loading document failed error.
  13. +
  14. Initialize a new empty active context. + The base IRI of the active context is set to the IRI of the currently being processed document, if available; + otherwise to null. + If set, the base option from options overrides the base IRI.
  15. +
  16. If an expandContext option has been passed, + update the active context using the Context Processing algorithm, + passing the expandContext as local context. + If expandContext is a dictionary having an @context member, + pass that member's value instead.
  17. +
  18. Once input has been retrieved, + the response has an HTTP Link Header [[RFC8288]] using the http://www.w3.org/ns/json-ld#context link relation + and a Content-Type of application/json + or any media type with a +json suffix as defined in [[RFC6839]] + except application/ld+json, + update the active context using the Context Processing algorithm, + passing the context referenced in the HTTP Link Header as local context. + The HTTP Link Header is ignored for documents served as application/ld+json + or text/html. + If multiple HTTP Link Headers using the http://www.w3.org/ns/json-ld#context link relation are found, + the promise is rejected with a JsonLdError whose code is set to multiple context link headers and processing is terminated.
  19. -
  20. If necessary, transform input into the - internal representation. If input cannot be transformed to the - internal representation, reject promise passing a - loading document failed error.
  21. -
  22. Set expanded output to the result of using the - Expansion algorithm, passing the - active context and input as element, - and if passed, the - frameExpansion +
  23. If the retrieved document's Content-Type is text/html + and the passed input is + a string representing the IRI of a remote document, + extract the content of the JSON-LD script element(s) into original input: +
      +
    1. If the original passed input parameter + contains a fragment identifier, + set source to the textContent + of the script element in input + having an id attribute + that matches the fragment identifier, after decoding percent encoded sequences. + If no element is found + or the located element is not a script element with type application/ld+json, + reject promise passing an invalid script element error. + Set original input to the result of the Extract Script Content algorithm, + using source.
    2. +
    3. Otherwise, if the extractAllScripts option is not present, or false, + locate the first JSON-LD script element in input, + and set source to its textContent, if found. + Set original input to the result of the Extract Script Content algorithm, + using source. + If no JSON-LD script element is found, set original input to a new empty array.
    4. +
    5. Otherwise, set original input to a new empty array. + For each JSON-LD script element in input: +
        +
      1. Set source to its textContent.
      2. +
      3. Set script content to the result of the Extract Script Content algorithm, + using source.
      4. +
      5. If script content is an array, merge it to the end of original input.
      6. +
      7. Otherwise, append script content to original input.
      8. +
      +
    6. +
    +
  24. +
  25. If necessary, transform original input into the internal representation. + If input cannot be transformed to the internal representation, + reject promise passing a loading document failed error.
  26. +
  27. Set expanded output to the result of using the Expansion algorithm, + passing the active context and original input as element, + and if passed, the frameExpansion and ordered flags in options.
  28. -
  29. Fulfill the promise passing expanded output. +
  30. Fulfill the promise passing expanded output transforming expanded output from the internal representation to a JSON serialization.
input
-
The dictionary or array of dictionaries to perform the expansion upon or an - IRI referencing the JSON-LD document to expand.
+
The dictionary, + or array of dictionaries to perform the expansion upon, + or an IRI referencing the JSON-LD document to expand.
options
-
A set of options to configure the used algorithms. This allows, e.g., - to set the input document's base IRI.
+
A set of options to configure the used algorithms. + This allows, e.g., to set the input document's base IRI.
flatten
-

Flattens the given input and - compacts it using the passed context +

Flattens the given input + and compacts it using the passed context according to the steps in the Flattening algorithm:

    -
  1. Create a new Promise promise and return it. The - following steps are then executed asynchronously.
  2. -
  3. Set expanded input to the result of using the - expand - method using input and options - with ordered set to false.
  4. -
  5. If context is a dictionary having an @context member, set - context to that member's value, otherwise to context.
  6. +
  7. Create a new Promise promise and return it. + The following steps are then executed asynchronously.
  8. +
  9. Set expanded input to the result of using the expand method + using input + and options + with ordered set to false, + and extractAllScripts defaulting to true.
  10. +
  11. If context is a dictionary having an @context member, + set context to that member's value, + otherwise to context.
  12. Initialize an active context using context; - the base IRI is set to - the base option from - options, if set; - otherwise, if the - compactToRelative option is - true, to the IRI of the currently being processed - document, if available; otherwise to null.
  13. + the base IRI is set to the base option + from options, if set; + otherwise, if the compactToRelative option is true, + to the IRI of the currently being processed document, if available; + otherwise to null.
  14. Initialize an empty identifier map.
  15. -
  16. Set flattened output to the result of using the - Flattening algorithm, passing - expanded input as element, active context, and if passed, the - compactArrays +
  17. Set flattened output to the result of using the Flattening algorithm, + passing expanded input as element, + active context, + and if passed, the compactArrays and ordered flags in options.
  18. -
  19. Fulfill the promise passing flattened output. +
  20. Fulfill the promise passing flattened output transforming flattened output from the internal representation to a JSON serialization.
input
-
The dictionary or array of dictionaries or an IRI - referencing the JSON-LD document to flatten.
+
The dictionary, + or array of dictionaries, + or an IRI referencing the JSON-LD document to flatten.
context
The context to use when compacting the flattened expanded input; - it can be specified by using a dictionary, an - IRI, or an array consisting of dictionaries - and IRIs. If not - passed or null is passed, the result will not be compacted - but kept in expanded form.
+ it can be specified by using a dictionary, + an IRI, or an array consisting of dictionaries + and IRIs. + If not passed or null is passed, + the result will not be compacted but kept in expanded form.
options
-
A set of options to configure the used algorithms. This allows, e.g., - to set the input document's base IRI.
+
A set of options to configure the used algorithms. + This allows, e.g., to set the input document's base IRI.
fromRdf
-

Transforms the given input into - a JSON-LD document in expanded form +

Transforms the given input + into a JSON-LD document in expanded form according to the steps in the Serialize RDF as JSON-LD Algorithm:

-

This interface does not define a means of creating - an RdfDataset from an arbitrary input, other than the - toRdf method.

+

This interface does not define a means of creating an RdfDataset + from an arbitrary input, other than the toRdf method.

    -
  1. Create a new Promise promise and return it. The - following steps are then executed asynchronously.
  2. +
  3. Create a new Promise promise and return it. + The following steps are then executed asynchronously.
  4. Set expanded result to the result of invoking the - Serialize RDF as JSON-LD Algorithm - method using dataset + Serialize RDF as JSON-LD Algorithm method + using dataset and options.
  5. Create a new RdfDataset dataset.
  6. Create a new dictionary node map.
  7. Invoke the - Node Map Generation algorithm, passing - expanded input as element and node map.
  8. + Node Map Generation algorithm, + passing expanded input as element + and node map.
  9. Invoke the Deserialize JSON-LD to RDF Algorithm - passing node map, dataset, and if passed, the - produceGeneralizedRdf flag in options - options. + passing node map, + dataset, + and if passed, the produceGeneralizedRdf flag in options.
    The use of blank node identifiers to label properties is obsolete, and may be removed in a future version of JSON-LD, as is the support for generalized RDF Datasets @@ -4919,11 +5009,12 @@

    The JsonLdProcessor Interface

    input
    -
    The dictionary or array of dictionaries or an IRI - referencing the JSON-LD document to flatten.
    +
    The dictionary, + or array of dictionaries, + or an IRI referencing the JSON-LD document to flatten.
    options
    -
    A set of options to configure the used algorithms. This allows, e.g., - to set the input document's base IRI.
    +
    A set of options to configure the used algorithms. + This allows, e.g., to set the input document's base IRI.
@@ -4933,21 +5024,22 @@

The JsonLdProcessor Interface

according to the steps in the Deserialize JSON-LD to RDF Algorithm:

    -
  1. Create a new Promise promise and return it. The - following steps are then executed asynchronously.
  2. +
  3. Create a new Promise promise and return it. + The following steps are then executed asynchronously.
  4. Set expanded input to the result of using the - expand - method using input - and options.
  5. + expand method + using input + and options + with ordered set to false, + and extractAllScripts defaulting to true.
  6. Create a new RdfDataset dataset.
  7. Create a new dictionary node map.
  8. -
  9. Invoke the - Node Map Generation algorithm, passing - expanded input as element and node map.
  10. -
  11. Invoke the - Deserialize JSON-LD to RDF Algorithm - passing node map, dataset, and if passed, the - produceGeneralizedRdf flag in options. +
  12. Invoke the Node Map Generation algorithm, + passing expanded input as element + and node map.
  13. +
  14. Invoke the Deserialize JSON-LD to RDF Algorithm + passing node map, dataset, + and if passed, the produceGeneralizedRdf flag in options.
    The use of blank node identifiers to label properties is obsolete, and may be removed in a future version of JSON-LD, as is the support for generalized RDF Datasets @@ -4958,11 +5050,12 @@

    The JsonLdProcessor Interface

    input
    -
    The dictionary or array of dictionaries or an IRI - referencing the JSON-LD document to flatten.
    +
    The dictionary, + or array of dictionaries, + or an IRI referencing the JSON-LD document to flatten.
    options
    -
    A set of options to configure the used algorithms. This allows, e.g., - to set the input document's base IRI.
    +
    A set of options to configure the used algorithms. + This allows, e.g., to set the input document's base IRI.
    @@ -4971,31 +5064,38 @@

    The JsonLdProcessor Interface

    dictionary JsonLdDictionary {}; -->

    The JsonLdDictionary is the definition of a dictionary - used to contain arbitrary dictionary members which are the result of - parsing a JSON Object. + used to contain arbitrary dictionary members + which are the result of parsing a JSON Object.

    -

    The JsonLdInput type is used to refer to an input value that - that may be a dictionary, an array of dictionaries or a string representing an - IRI which an be dereferenced to retrieve a valid JSON document.

    +

    The JsonLdInput type is used to refer to an input value + that that may be a dictionary, + an array of dictionaries , + or a string representing an IRI + which can be dereferenced to retrieve a valid JSON document.

    -

    The JsonLdContext type is used to refer to a value that - that may be a dictionary, a string representing an - IRI, or an array of dictionaries - and strings.

    +

    The JsonLdContext type is used to refer to a value + that may be a dictionary, + a string representing an IRI, + or an array of dictionaries and strings.

RDF Dataset Interfaces

-

The RdfDataset interface describes operations on an RDF dataset used by the fromRdf and toRdf methods in the JsonLdProcessor interface. The interface may be used for constructing a new RDF dataset, which has a default graph accessible via the defaultGraph attribute.

+

The RdfDataset interface describes operations on an RDF dataset + used by the fromRdf + and toRdf methods + in the JsonLdProcessor interface. + The interface may be used for constructing a new RDF dataset, + which has a default graph accessible via the defaultGraph attribute.

       [Constructor]
@@ -5011,7 +5111,8 @@ 

RDF Dataset Interfaces

Provides access to the default graph associated with the RDF dataset.
add
-

Adds an RdfGraph and its associated graph name to the RdfDataset. Used by the Deserialize JSON-LD to RDF Algorithm.

+

Adds an RdfGraph and its associated graph name to the RdfDataset. + Used by the Deserialize JSON-LD to RDF Algorithm.

graphName
@@ -5024,13 +5125,19 @@

RDF Dataset Interfaces

iterable
The value pairs to iterate over - are the list of graph name-graph pairs, with the - graph name being null (for the default - graph), an IRI or blank node identifier and graph an - RdfGraph instance.
+ are the list of graph name-graph pairs, + with the graph name being null + (for the default graph), + an IRI, + or blank node identifier + and graph an RdfGraph instance. -

The RdfGraph interface describes operations on an RDF graph used by the fromRdf and toRdf methods in the JsonLdProcessor interface. The interface may be used for constructing a new RDF graph, which is composed of zero or more RdfTriple instances.

+

The RdfGraph interface describes operations on an RDF graph used by the fromRdf + and toRdf methods + in the JsonLdProcessor interface. + The interface may be used for constructing a new RDF graph, + which is composed of zero or more RdfTriple instances.

       [Constructor]
@@ -5043,7 +5150,8 @@ 

RDF Dataset Interfaces

add
-

Adds an RdfTriple to the RdfGraph. Used by the Deserialize JSON-LD to RDF Algorithm.

+

Adds an RdfTriple to the RdfGraph. + Used by the Deserialize JSON-LD to RDF Algorithm.

triple
@@ -5052,9 +5160,9 @@

RDF Dataset Interfaces

iterable
A value iterator - over the RdfTriple instances associated with the graph. - Note that a given RdfTriple instance may appear - in more than one graph within a particular RdfDataset instance.
+ over the RdfTriple instancesassociated with the graph. + Note that a given RdfTriple instance may appear in more than one graph + within a particular RdfDataset instance.

The RdfTriple interface describes an RDF Triple.

@@ -5070,15 +5178,18 @@

RDF Dataset Interfaces

subject
-
An absolute IRI or blank node identifier denoting the subject of the triple.
+
An absolute IRI or blank node identifier + denoting the subject of the triple.
predicate
An absolute IRI denoting the predicate of the triple. - If used to represent a Generalized RDF Dataset, it may also be a blank node identifier. + If used to represent a Generalized RDF Dataset, + it may also be a blank node identifier.
The use of blank node identifiers to label properties is obsolete, and may be removed in a future version of JSON-LD, as is the support for generalized RDF Datasets.
object
-
An absolute IRI, blank node identifier or literal denoting the object of the triple.
+
An absolute IRI, blank node identifier, or literal + denoting the object of the triple.

The RdfLiteral interface describes an RDF Literal.

@@ -5097,10 +5208,11 @@

RDF Dataset Interfaces

The lexical value of the literal.
datatype
An absolute IRI denoting the datatype IRI of the literal. - If the value is rdf:langString, language MUST be specified.
+ If the value is rdf:langString, + language MUST be specified.
language
-
An optional language tag as defined by [[BCP47]]. If this value is specified, - datatype MUST be rdf:langString
+
An optional language tag as defined by [[BCP47]]. + If this value is specified, datatype MUST be rdf:langString.
@@ -5117,6 +5229,7 @@

The JsonLdOptions Type

boolean compactToRelative = true; LoadDocumentCallback documentLoader = null; (JsonLdDictionary? or USVString) expandContext = null; + boolean extractAllScripts = false; boolean frameExpansion = false; boolean ordered = false; USVString processingMode = null; @@ -5128,22 +5241,29 @@

The JsonLdOptions Type

base
-
The base IRI to use when expanding or compacting the document. If set, this overrides - the input document's IRI.
+
The base IRI to use when expanding or compacting the document. + If set, this overrides the input document's IRI.
compactArrays
-
If set to true, the JSON-LD processor replaces arrays with just - one element with that element during compaction. If set to false, +
If set to true, the JSON-LD processor replaces arrays + with just one element with that element during compaction. + If set to false, all arrays will remain arrays even if they have just one element.
documentLoader
The callback of the loader to be used to retrieve remote documents and contexts. - If specified, it is used to retrieve remote documents and contexts; otherwise, - if not specified, the processor's built-in loader is used.
+ If specified, it is used to retrieve remote documents and contexts; + otherwise, if not specified, the processor's built-in loader is used.
expandContext
A context that is used to initialize the active context when expanding a document.
+
extractAllScripts
+
If set to true, + when extracting JSON-LD script elements from HTML, + unless a specific fragment identifier is targeted, + extracts all encountered JSON-LD script elements using an array form, if necessary.
produceGeneralizedRdf
-
If set to true, the JSON-LD processor may emit blank nodes for - triple predicates, otherwise they will be omitted. +
If set to true, the JSON-LD processor may emit + blank nodes for triple predicates, + otherwise they will be omitted. Generalized RDF Datasets are defined in [[RDF11-CONCEPTS]].
The use of blank node identifiers to label properties is obsolete, @@ -5153,20 +5273,21 @@

The JsonLdOptions Type

processingMode
Sets the processing mode. - If set to json-ld-1.0 or json-ld-1.1, the - implementation must produce exactly the same results as the algorithms - defined in this specification. - If set to another value, the JSON-LD processor is allowed to extend - or modify the algorithms defined in this specification to enable - application-specific optimizations. The definition of such - optimizations is beyond the scope of this specification and thus - not defined. Consequently, different implementations may implement - different optimizations. Developers must not define modes beginning - with json-ld as they are reserved for future versions - of this specification.
+ If set to json-ld-1.0 or json-ld-1.1, + the implementation must produce exactly the same results as the + algorithms defined in this specification. + If set to another value, + the JSON-LD processor is allowed to extend or modify the algorithms defined in this specification + to enable application-specific optimizations. + The definition of such optimizations is beyond the scope of this specification + and thus not defined. + Consequently, different implementations may implement different optimizations. + Developers must not define modes beginning with json-ld + as they are reserved for future versions of this specification.
compactToRelative
-
Determines if IRIs are compacted relative to the - base option or document location when compacting.
+
Determines if IRIs are compacted + relative to the base option + or document location when compacting.
frameExpansion
Enables special frame processing rules for the Expansion Algorithm.
Enables special rules for the Serialize RDF as JSON-LD Algorithm @@ -5178,19 +5299,19 @@

The JsonLdOptions Type

Enables special rules for the Serialize RDF as JSON-LD Algorithm causing rdf:type properties to be kept as IRIs in the output, rather than use @type.
ordered
-
If set to true, certain algorithm - processing steps where indicated are ordered lexicographically. - If false, order - is not considered in processing.
+
If set to true, + certain algorithm processing steps where indicated are ordered lexicographically. + If false, order is not considered in processing.

Remote Document and Context Retrieval

-

Users of an API implementation can utilize a callback to control how remote - documents and contexts are retrieved. This section details the parameters of - that callback and the data structure used to return the retrieved context.

+

Users of an API implementation can utilize a callback to control how + remote documents and contexts are retrieved. + This section details the parameters of that callback + and the data structure used to return the retrieved context.

LoadDocumentCallback

@@ -5207,9 +5328,8 @@

LoadDocumentCallback

The URL of the remote document or context to load.
-

All errors result in the Promise being rejected with - a JsonLdError whose code is set to - loading document failed +

All errors result in the Promise being rejected with a JsonLdError + whose code is set to loading document failed or multiple context link headers as described in the next section.

@@ -5225,25 +5345,29 @@

RemoteDocument

USVString contextUrl = null; USVString documentUrl; any document; + USVString contentType; }; -->
contextUrl
-
If available, the value of the HTTP Link Header [[RFC8288]] using the - http://www.w3.org/ns/json-ld#context link relation in the - response. If the response's content type is application/ld+json, - the HTTP Link Header is ignored. If multiple HTTP Link Headers using - the http://www.w3.org/ns/json-ld#context link relation are found, - the Promise of the LoadDocumentCallback is rejected with - a JsonLdError whose code is set to - multiple context link headers.
+
If available, the value of the HTTP Link Header [[RFC8288]] + using the http://www.w3.org/ns/json-ld#context link relation + in the response. + If the response's Content-Type is application/ld+json, + the HTTP Link Header is ignored. + If multiple HTTP Link Headers using the http://www.w3.org/ns/json-ld#context link relation are found, + the Promise of the LoadDocumentCallback is rejected + with a JsonLdError whose code is set to multiple context link headers.
documentUrl
-
The final URL of the loaded document. This is important - to handle HTTP redirects properly.
+
The final URL of the loaded document. + This is important to handle HTTP redirects properly.
document
-
The retrieved document. This can either be the raw payload or the already - parsed document.
+
The retrieved document. + This can either be the raw payload or the already parsed document.
+
contentType
+
The Content-Type + of the loaded document.
@@ -5251,8 +5375,8 @@

RemoteDocument

Error Handling

-

This section describes the datatype definitions used within the - JSON-LD API for error handling.

+

This section describes the datatype definitions + used within the JSON-LD API for error handling.

JsonLdError

@@ -5268,19 +5392,17 @@

JsonLdError

code
-
a string representing the particular error type, as described in - the various algorithms in this document.
+
A string representing the particular error type, + as described in the various algorithms in this document.
message
-
an optional error message containing additional debugging information. - The specific contents of error messages are outside the scope of this - specification.
+
An optional error message containing additional debugging information. + The specific contents of error messages are outside the scope of this specification.

JsonLdErrorCode

-

The JsonLdErrorCode represents the collection of valid JSON-LD error - codes.

+

The JsonLdErrorCode represents the collection of valid JSON-LD error codes.


+    
+  
+
\ No newline at end of file
diff --git a/tests/expand/h008-out.jsonld b/tests/expand/h008-out.jsonld
new file mode 100644
index 00000000..e793da70
--- /dev/null
+++ b/tests/expand/h008-out.jsonld
@@ -0,0 +1,3 @@
+[{
+  "http://example.com/foo": [{"@list": [{"@value": "bar"}]}]
+}]
\ No newline at end of file
diff --git a/tests/expand/h009-in.html b/tests/expand/h009-in.html
new file mode 100644
index 00000000..1a85b642
--- /dev/null
+++ b/tests/expand/h009-in.html
@@ -0,0 +1,13 @@
+
+  
+    
+  
+
\ No newline at end of file
diff --git a/tests/expand/h009-out.jsonld b/tests/expand/h009-out.jsonld
new file mode 100644
index 00000000..44cc49c8
--- /dev/null
+++ b/tests/expand/h009-out.jsonld
@@ -0,0 +1,6 @@
+[{
+  "http://example/comment-start": [{"@value": ""}],
+  "http://example/script-start": [{"@value": ""}]
+}]
\ No newline at end of file
diff --git a/tests/expand/h010-in.html b/tests/expand/h010-in.html
new file mode 100644
index 00000000..384ea36e
--- /dev/null
+++ b/tests/expand/h010-in.html
@@ -0,0 +1,10 @@
+
+  
+    
+  
+
\ No newline at end of file
diff --git a/tests/expand/h010-out.jsonld b/tests/expand/h010-out.jsonld
new file mode 100644
index 00000000..4246a085
--- /dev/null
+++ b/tests/expand/h010-out.jsonld
@@ -0,0 +1,3 @@
+[{
+  "http://example/foo": [{"@value": "<&>"}]
+}]
\ No newline at end of file
diff --git a/tests/expand/h011-in.html b/tests/expand/h011-in.html
new file mode 100644
index 00000000..f18c1dae
--- /dev/null
+++ b/tests/expand/h011-in.html
@@ -0,0 +1,21 @@
+
+  
+    
+    
+  
+
\ No newline at end of file
diff --git a/tests/expand/h012-in.html b/tests/expand/h012-in.html
new file mode 100644
index 00000000..7700c932
--- /dev/null
+++ b/tests/expand/h012-in.html
@@ -0,0 +1,12 @@
+
+  
+    
+    {
+      "@context": {
+        "foo": {"@id": "http://example.com/foo", "@container": "@list"}
+      },
+      "foo": [{"@value": "bar"}]
+    }
+    
+ + \ No newline at end of file diff --git a/tests/expand/h013-in.html b/tests/expand/h013-in.html new file mode 100644 index 00000000..4e0d64a4 --- /dev/null +++ b/tests/expand/h013-in.html @@ -0,0 +1,12 @@ + + + + + \ No newline at end of file diff --git a/tests/expand/h014-in.html b/tests/expand/h014-in.html new file mode 100644 index 00000000..ceeeff8b --- /dev/null +++ b/tests/expand/h014-in.html @@ -0,0 +1,14 @@ + + + + + \ No newline at end of file diff --git a/tests/expand/h015-in.html b/tests/expand/h015-in.html new file mode 100644 index 00000000..eb0e188a --- /dev/null +++ b/tests/expand/h015-in.html @@ -0,0 +1,13 @@ + + + + + \ No newline at end of file diff --git a/tests/expand/h016-in.html b/tests/expand/h016-in.html new file mode 100644 index 00000000..1bc35a18 --- /dev/null +++ b/tests/expand/h016-in.html @@ -0,0 +1,13 @@ + + + + + \ No newline at end of file diff --git a/tests/expand/h017-in.html b/tests/expand/h017-in.html new file mode 100644 index 00000000..90a0e2f6 --- /dev/null +++ b/tests/expand/h017-in.html @@ -0,0 +1,7 @@ + + + + + \ No newline at end of file diff --git a/tests/flatten-manifest.jsonld b/tests/flatten-manifest.jsonld index adbbcc37..be4c3dcb 100644 --- a/tests/flatten-manifest.jsonld +++ b/tests/flatten-manifest.jsonld @@ -348,6 +348,42 @@ "option": {"specVersion": "json-ld-1.1"}, "input": "flatten/e001-in.jsonld", "expect": "conflicting indexes" + }, { + "@id": "#th001", + "@type": ["jld:PositiveEvaluationTest", "jld:FlattenTest"], + "name": "Flattens embedded JSON-LD script element", + "purpose": "Tests embedded JSON-LD in HTML", + "input": "flatten/h001-in.html", + "context": "flatten/h001-context.jsonld", + "expect": "flatten/h001-out.jsonld", + "option": {"specVersion": "json-ld-1.1"} + }, { + "@id": "#th002", + "@type": ["jld:PositiveEvaluationTest", "jld:FlattenTest"], + "name": "Flattens first embedded JSON-LD script element", + "purpose": "Tests embedded JSON-LD in HTML", + "input": "flatten/h002-in.html", + "context": "flatten/h002-context.jsonld", + "expect": "flatten/h002-out.jsonld", + "option": {"specVersion": "json-ld-1.1", "extractAllScripts": false} + }, { + "@id": "#th003", + "@type": ["jld:PositiveEvaluationTest", "jld:FlattenTest"], + "name": "Flattens targeted JSON-LD script element", + "purpose": "Tests embedded JSON-LD in HTML with fragment identifier", + "input": "flatten/h003-in.html#second", + "context": "flatten/h003-context.jsonld", + "expect": "flatten/h003-out.jsonld", + "option": {"specVersion": "json-ld-1.1"} + }, { + "@id": "#th004", + "@type": ["jld:PositiveEvaluationTest", "jld:FlattenTest"], + "name": "Flattens all script elements by default", + "purpose": "Tests embedded JSON-LD in HTML with fragment identifier", + "input": "flatten/h004-in.html", + "context": "flatten/h004-context.jsonld", + "expect": "flatten/h004-out.jsonld", + "option": {"specVersion": "json-ld-1.1"} }, { "@id": "#tli01", "@type": [ "jld:PositiveEvaluationTest", "jld:FlattenTest" ], diff --git a/tests/flatten/h001-context.jsonld b/tests/flatten/h001-context.jsonld new file mode 100644 index 00000000..c9ee5d89 --- /dev/null +++ b/tests/flatten/h001-context.jsonld @@ -0,0 +1,5 @@ +{ + "@context": { + "foo": {"@id": "http://example.com/foo", "@container": "@list"} + } +} \ No newline at end of file diff --git a/tests/flatten/h001-in.html b/tests/flatten/h001-in.html new file mode 100644 index 00000000..57328e38 --- /dev/null +++ b/tests/flatten/h001-in.html @@ -0,0 +1,12 @@ + + + + + \ No newline at end of file diff --git a/tests/flatten/h001-out.jsonld b/tests/flatten/h001-out.jsonld new file mode 100644 index 00000000..b62c9ff4 --- /dev/null +++ b/tests/flatten/h001-out.jsonld @@ -0,0 +1,7 @@ +{ + "@context": { + "foo": {"@id": "http://example.com/foo", "@container": "@list"} + }, + "@graph": [{"@id": "_:b0","foo": ["bar"]} + ] +} \ No newline at end of file diff --git a/tests/flatten/h002-context.jsonld b/tests/flatten/h002-context.jsonld new file mode 100644 index 00000000..c9ee5d89 --- /dev/null +++ b/tests/flatten/h002-context.jsonld @@ -0,0 +1,5 @@ +{ + "@context": { + "foo": {"@id": "http://example.com/foo", "@container": "@list"} + } +} \ No newline at end of file diff --git a/tests/flatten/h002-in.html b/tests/flatten/h002-in.html new file mode 100644 index 00000000..b287ab50 --- /dev/null +++ b/tests/flatten/h002-in.html @@ -0,0 +1,21 @@ + + + + + + \ No newline at end of file diff --git a/tests/flatten/h002-out.jsonld b/tests/flatten/h002-out.jsonld new file mode 100644 index 00000000..b62c9ff4 --- /dev/null +++ b/tests/flatten/h002-out.jsonld @@ -0,0 +1,7 @@ +{ + "@context": { + "foo": {"@id": "http://example.com/foo", "@container": "@list"} + }, + "@graph": [{"@id": "_:b0","foo": ["bar"]} + ] +} \ No newline at end of file diff --git a/tests/flatten/h003-context.jsonld b/tests/flatten/h003-context.jsonld new file mode 100644 index 00000000..bd58ee54 --- /dev/null +++ b/tests/flatten/h003-context.jsonld @@ -0,0 +1,3 @@ +{ + "@context": {"ex": "http://example.com/"} +} \ No newline at end of file diff --git a/tests/flatten/h003-in.html b/tests/flatten/h003-in.html new file mode 100644 index 00000000..f18c1dae --- /dev/null +++ b/tests/flatten/h003-in.html @@ -0,0 +1,21 @@ + + + + + + \ No newline at end of file diff --git a/tests/flatten/h003-out.jsonld b/tests/flatten/h003-out.jsonld new file mode 100644 index 00000000..cd0c43e1 --- /dev/null +++ b/tests/flatten/h003-out.jsonld @@ -0,0 +1,7 @@ +{ + "@context": {"ex": "http://example.com/"}, + "@graph": [ + {"@id": "_:b0", "ex:foo": "foo"}, + {"@id": "_:b1", "ex:bar": "bar"} + ] +} \ No newline at end of file diff --git a/tests/flatten/h004-context.jsonld b/tests/flatten/h004-context.jsonld new file mode 100644 index 00000000..c68c329c --- /dev/null +++ b/tests/flatten/h004-context.jsonld @@ -0,0 +1,6 @@ +{ + "@context": { + "ex": "http://example.com/", + "foo": {"@id": "http://example.com/foo", "@container": "@list"} + } +} \ No newline at end of file diff --git a/tests/flatten/h004-in.html b/tests/flatten/h004-in.html new file mode 100644 index 00000000..cfac7160 --- /dev/null +++ b/tests/flatten/h004-in.html @@ -0,0 +1,18 @@ + + + + + + \ No newline at end of file diff --git a/tests/flatten/h004-out.jsonld b/tests/flatten/h004-out.jsonld new file mode 100644 index 00000000..e0315dd2 --- /dev/null +++ b/tests/flatten/h004-out.jsonld @@ -0,0 +1,11 @@ +{ + "@context": { + "ex": "http://example.com/", + "foo": {"@id": "http://example.com/foo", "@container": "@list"} + }, + "@graph": [ + {"@id": "_:b0", "foo": ["bar"]}, + {"@id": "_:b1", "ex:foo": "foo"}, + {"@id": "_:b2", "ex:bar": "bar"} + ] +} \ No newline at end of file diff --git a/tests/toRdf-manifest.jsonld b/tests/toRdf-manifest.jsonld index 8402e443..6a9ab44c 100644 --- a/tests/toRdf-manifest.jsonld +++ b/tests/toRdf-manifest.jsonld @@ -877,6 +877,30 @@ "purpose": "IRI resolution according to RFC3986.", "input": "toRdf/0129-in.jsonld", "expect": "toRdf/0129-out.nq" + }, { + "@id": "#th001", + "@type": ["jld:PositiveEvaluationTest", "jld:ToRDFTest"], + "name": "Transforms embedded JSON-LD script element", + "purpose": "Tests embedded JSON-LD in HTML", + "input": "toRdf/h001-in.html", + "expect": "toRdf/h001-out.nq", + "option": {"specVersion": "json-ld-1.1"} + }, { + "@id": "#th002", + "@type": ["jld:PositiveEvaluationTest", "jld:ToRDFTest"], + "name": "Transforms first embedded JSON-LD script element", + "purpose": "Tests embedded JSON-LD in HTML", + "input": "toRdf/h002-in.html", + "expect": "toRdf/h002-out.nq", + "option": {"specVersion": "json-ld-1.1", "extractAllScripts": false} + }, { + "@id": "#th003", + "@type": ["jld:PositiveEvaluationTest", "jld:ToRDFTest"], + "name": "Transforms targeted JSON-LD script element", + "purpose": "Tests embedded JSON-LD in HTML with fragment identifier", + "input": "toRdf/h003-in.html#second", + "expect": "toRdf/h003-out.nq", + "option": {"specVersion": "json-ld-1.1"} }, { "@id": "#tli01", "@type": ["jld:PositiveEvaluationTest", "jld:ToRDFTest"], diff --git a/tests/toRdf/h001-in.html b/tests/toRdf/h001-in.html new file mode 100644 index 00000000..5f7274ed --- /dev/null +++ b/tests/toRdf/h001-in.html @@ -0,0 +1,12 @@ + + + + +) \ No newline at end of file diff --git a/tests/toRdf/h001-out.nq b/tests/toRdf/h001-out.nq new file mode 100644 index 00000000..91e9e279 --- /dev/null +++ b/tests/toRdf/h001-out.nq @@ -0,0 +1,3 @@ +_:b0 _:b1 . +_:b1 "bar" . +_:b1 . diff --git a/tests/toRdf/h002-in.html b/tests/toRdf/h002-in.html new file mode 100644 index 00000000..b287ab50 --- /dev/null +++ b/tests/toRdf/h002-in.html @@ -0,0 +1,21 @@ + + + + + + \ No newline at end of file diff --git a/tests/toRdf/h002-out.nq b/tests/toRdf/h002-out.nq new file mode 100644 index 00000000..91e9e279 --- /dev/null +++ b/tests/toRdf/h002-out.nq @@ -0,0 +1,3 @@ +_:b0 _:b1 . +_:b1 "bar" . +_:b1 . diff --git a/tests/toRdf/h003-in.html b/tests/toRdf/h003-in.html new file mode 100644 index 00000000..f18c1dae --- /dev/null +++ b/tests/toRdf/h003-in.html @@ -0,0 +1,21 @@ + + + + + + \ No newline at end of file diff --git a/tests/toRdf/h003-out.nq b/tests/toRdf/h003-out.nq new file mode 100644 index 00000000..44f69e9a --- /dev/null +++ b/tests/toRdf/h003-out.nq @@ -0,0 +1,2 @@ +_:b0 "foo" . +_:b1 "bar" .