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 @@
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
.
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. +
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 +
<\script
,
+ <\/script
,
+ <\!--
,
+ or --\>
+ in source using a case-insenstive match,
+ replace the sequence with the equivalent sequence excluding the REVERSE SOLIDUS (\
).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:
false
.
- @context
member, set
- context to that member's value, otherwise to context.false
,
+ and extractAllScripts defaulting to false
.
+ @context
member,
+ set context to that member's value,
+ otherwise to context.null
.null
.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.input
;
- it can be specified by using a dictionary, an
- IRI, or an array consisting of
- dictionaries and IRIs.Expands the given input according to - the steps in the Expansion algorithm:
+Expands the given input + according to the steps in the Expansion algorithm:
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.null
. If set, the
- base option from options overrides the base IRI.@context
member, pass that member's value instead.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
+ 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.null
.
+ If set, the base option from options overrides the base IRI.@context
member,
+ pass that member's value instead.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.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:
+ 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.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.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:
false
.@context
member, set
- context to that member's value, otherwise to context.false
,
+ and extractAllScripts defaulting to true
.@context
member,
+ set context to that member's value,
+ otherwise to context.null
.null
.
null
is passed, the result will not be compacted
- but kept in expanded form.null
is passed,
+ the result will not be compacted but kept in expanded form.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.
false
,
+ and extractAllScripts defaulting to true
.
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.
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
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.
null
(for the default
- graph), an IRI or blank node identifier and graph an
- RdfGraph instance.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
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.
The RdfTriple interface describes an RDF Triple.
@@ -5070,15 +5178,18 @@The RdfLiteral interface describes an RDF Literal.
@@ -5097,10 +5208,11 @@rdf:langString
, language MUST be specified.rdf:langString
,
+ language MUST be specified.
rdf:langString
rdf:langString
.true
, the JSON-LD processor replaces arrays with just
- one element with that element during compaction. If set to false
,
+ 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.
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.true
, the JSON-LD processor may emit blank nodes for
- triple predicates, otherwise they will be omitted.
+ 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]].
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.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.
rdf:type
properties to be kept as IRIs in the output, rather than use @type
.true
, certain algorithm
- processing steps where indicated are ordered lexicographically.
- If false
, order
- is not considered in processing.true
,
+ certain algorithm processing steps where indicated are ordered lexicographically.
+ If false
, order is not considered in processing.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.
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.
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.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.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.
The JsonLdErrorCode represents the collection of valid JSON-LD error - codes.
+The JsonLdErrorCode represents the collection of valid JSON-LD error codes.
+ + +