Skip to content

Commit

Permalink
Add support for pattern properties
Browse files Browse the repository at this point in the history
Convert the patterns to actual RegExp objects and then render them as such.
This is especially useful for the perfectly valid empty pattern, which
otherwise would not appear.

Add a function, `propertySpecs`, which returns specs for handling both
properties and patternProperties, and then iterate over them both to produce
both the summary table and the more detailed info. Right now it creates a
separate table for patter properties, but it might be worth considering a
single table, since the rendering of the regex makes it pretty clear which
is which.

Add tests for pattern properties, too.
  • Loading branch information
theory committed Mar 11, 2022
1 parent 189f3f8 commit fb4db4a
Show file tree
Hide file tree
Showing 11 changed files with 448 additions and 142 deletions.
301 changes: 161 additions & 140 deletions lib/generateMarkdown.js

Large diffs are not rendered by default.

5 changes: 3 additions & 2 deletions lib/style.js
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ function styleBold(string) {
function styleCode(code) {
if (defined(code)) {
// If it's an object, just serialize it.
if (typeof code === 'object') {
if (typeof code === 'object' && code.constructor != RegExp) {
// Someday may want to use a code fence if it's longer than, say, 88
// chars, but that would require keeping track of the current
// indentation. Not really how things are designed to work right
Expand All @@ -353,7 +353,8 @@ function styleCode(code) {
var stringified = code.toString();

if (stringified.length > 0) {
return '`' + stringified + '`';
// Escape ` so it doesn't end early, and | so it works in a table cell.
return '`' + stringified.replaceAll(/([`|])/g, '\\$1') + '`';
}
}

Expand Down
38 changes: 38 additions & 0 deletions test/test-golden/v2020-12-embed.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,22 @@ Image data used to create a texture. Image **MAY** be referenced by an URI (or I

|===

.`Image` Pattern Properties
|===
| |Type|Description|Required

|**`/^(?:rgb\|hex\|hsl\|rgba\|hsla)Color/`**
|`string`
|The background color for the image
|No

|**`/^(?:height\|width)$/`**
|`string`
|A dimension for the image
|No

|===

Additional properties are allowed.

* **JSON schema**: <<schema-reference-image,`image.schema.json`>>
Expand Down Expand Up @@ -93,6 +109,28 @@ An array of three fractional numbers.
** `[18, 0.1, 1.1]`


=== Image.`/^(?:rgb\|hex\|hsl\|rgba\|hsla)Color/`

The background color for the image

* **Type**: `string`
* **Required**: No
* **Examples**:
** `"rgb(255, 99, 71)"`
** `"#ff6347"`
** `"hsl(9, 100%, 64%)"`

=== Image.`/^(?:height\|width)$/`

A dimension for the image

* **Type**: `string`
* **Required**: No
* **Examples**:
** `"10"`
** `"400px"`


== Examples

* `{"uri": "https://raw.githubusercontent.com/KhronosGroup/glTF/main/specification/figures/gltf.png", "mimeType": "image/png"}`
Expand Down
29 changes: 29 additions & 0 deletions test/test-golden/v2020-12-keyword.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,13 @@ Image data used to create a texture. Image **MAY** be referenced by an URI (or I
|**fraction**|`number`|A number that **MUST** be between zero and one.|No|
|**moreFractions**|`number` `[3]`|An array of three fractional numbers.|No, default: `[0.1,0.2,0.3]`|

**`Image` Pattern Properties**

| |Type|Description|Required|
|---|---|---|---|
|**`/^(?:rgb\|hex\|hsl\|rgba\|hsla)Color/`**|`string`|The background color for the image|No|
|**`/^(?:height\|width)$/`**|`string`|A dimension for the image|No|

Additional properties are allowed.

### Image.uri
Expand Down Expand Up @@ -72,6 +79,28 @@ An array of three fractional numbers.
* `[18, 0.1, 1.1]`


### Image.`/^(?:rgb\|hex\|hsl\|rgba\|hsla)Color/`

The background color for the image

* **Type**: `string`
* **Required**: No
* **Examples**:
* `"rgb(255, 99, 71)"`
* `"#ff6347"`
* `"hsl(9, 100%, 64%)"`

### Image.`/^(?:height\|width)$/`

A dimension for the image

* **Type**: `string`
* **Required**: No
* **Examples**:
* `"10"`
* `"400px"`


## Examples

* `{"uri": "https://raw.githubusercontent.com/KhronosGroup/glTF/main/specification/figures/gltf.png", "mimeType": "image/png"}`
Expand Down
38 changes: 38 additions & 0 deletions test/test-golden/v2020-12-linked.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,22 @@ Image data used to create a texture. Image **MAY** be referenced by an URI (or I

|===

.`Image` Pattern Properties
|===
| |Type|Description|Required

|**`/^(?:rgb\|hex\|hsl\|rgba\|hsla)Color/`**
|`string`
|The background color for the image
|No

|**`/^(?:height\|width)$/`**
|`string`
|A dimension for the image
|No

|===

Additional properties are allowed.

* **JSON schema**: link:schema/image.schema.json[image.schema.json]
Expand Down Expand Up @@ -95,6 +111,28 @@ An array of three fractional numbers.
** `[18, 0.1, 1.1]`


==== Image.`/^(?:rgb\|hex\|hsl\|rgba\|hsla)Color/`

The background color for the image

* **Type**: `string`
* **Required**: No
* **Examples**:
** `"rgb(255, 99, 71)"`
** `"#ff6347"`
** `"hsl(9, 100%, 64%)"`

==== Image.`/^(?:height\|width)$/`

A dimension for the image

* **Type**: `string`
* **Required**: No
* **Examples**:
** `"10"`
** `"400px"`


=== Examples

* `{"uri": "https://raw.githubusercontent.com/KhronosGroup/glTF/main/specification/figures/gltf.png", "mimeType": "image/png"}`
Expand Down
29 changes: 29 additions & 0 deletions test/test-golden/v2020-12-linked.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,13 @@ Image data used to create a texture. Image **MAY** be referenced by an URI (or I
|**fraction**|`number`|A number that **MUST** be between zero and one.|No|
|**moreFractions**|`number` `[3]`|An array of three fractional numbers.|No, default: `[0.1,0.2,0.3]`|

**`Image` Pattern Properties**

| |Type|Description|Required|
|---|---|---|---|
|**`/^(?:rgb\|hex\|hsl\|rgba\|hsla)Color/`**|`string`|The background color for the image|No|
|**`/^(?:height\|width)$/`**|`string`|A dimension for the image|No|

Additional properties are allowed.

* **JSON schema**: [image.schema.json](schema/image.schema.json)
Expand Down Expand Up @@ -74,6 +81,28 @@ An array of three fractional numbers.
* `[18, 0.1, 1.1]`


#### Image.`/^(?:rgb\|hex\|hsl\|rgba\|hsla)Color/`

The background color for the image

* **Type**: `string`
* **Required**: No
* **Examples**:
* `"rgb(255, 99, 71)"`
* `"#ff6347"`
* `"hsl(9, 100%, 64%)"`

#### Image.`/^(?:height\|width)$/`

A dimension for the image

* **Type**: `string`
* **Required**: No
* **Examples**:
* `"10"`
* `"400px"`


### Examples

* `{"uri": "https://raw.githubusercontent.com/KhronosGroup/glTF/main/specification/figures/gltf.png", "mimeType": "image/png"}`
Expand Down
38 changes: 38 additions & 0 deletions test/test-golden/v2020-12-remote.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,22 @@ Image data used to create a texture. Image **MAY** be referenced by an URI (or I

|===

.`Image` Pattern Properties
|===
| |Type|Description|Required

|**`/^(?:rgb\|hex\|hsl\|rgba\|hsla)Color/`**
|`string`
|The background color for the image
|No

|**`/^(?:height\|width)$/`**
|`string`
|A dimension for the image
|No

|===

Additional properties are allowed.

* **JSON schema**: link:https://www.khronos.org/wetzel/just/testing/schema/image.schema.json[image.schema.json]
Expand Down Expand Up @@ -93,6 +109,28 @@ An array of three fractional numbers.
** `[18, 0.1, 1.1]`


=== Image.`/^(?:rgb\|hex\|hsl\|rgba\|hsla)Color/`

The background color for the image

* **Type**: `string`
* **Required**: No
* **Examples**:
** `"rgb(255, 99, 71)"`
** `"#ff6347"`
** `"hsl(9, 100%, 64%)"`

=== Image.`/^(?:height\|width)$/`

A dimension for the image

* **Type**: `string`
* **Required**: No
* **Examples**:
** `"10"`
** `"400px"`


== Examples

* `{"uri": "https://raw.githubusercontent.com/KhronosGroup/glTF/main/specification/figures/gltf.png", "mimeType": "image/png"}`
Expand Down
29 changes: 29 additions & 0 deletions test/test-golden/v2020-12-remote.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,13 @@ Image data used to create a texture. Image **MAY** be referenced by an URI (or I
|**fraction**|`number`|A number that **MUST** be between zero and one.|No|
|**moreFractions**|`number` `[3]`|An array of three fractional numbers.|No, default: `[0.1,0.2,0.3]`|

**`Image` Pattern Properties**

| |Type|Description|Required|
|---|---|---|---|
|**`/^(?:rgb\|hex\|hsl\|rgba\|hsla)Color/`**|`string`|The background color for the image|No|
|**`/^(?:height\|width)$/`**|`string`|A dimension for the image|No|

Additional properties are allowed.

* **JSON schema**: [image.schema.json](https://www.khronos.org/wetzel/just/testing/schema/image.schema.json)
Expand Down Expand Up @@ -72,6 +79,28 @@ An array of three fractional numbers.
* `[18, 0.1, 1.1]`


### Image.`/^(?:rgb\|hex\|hsl\|rgba\|hsla)Color/`

The background color for the image

* **Type**: `string`
* **Required**: No
* **Examples**:
* `"rgb(255, 99, 71)"`
* `"#ff6347"`
* `"hsl(9, 100%, 64%)"`

### Image.`/^(?:height\|width)$/`

A dimension for the image

* **Type**: `string`
* **Required**: No
* **Examples**:
* `"10"`
* `"400px"`


## Examples

* `{"uri": "https://raw.githubusercontent.com/KhronosGroup/glTF/main/specification/figures/gltf.png", "mimeType": "image/png"}`
Expand Down
38 changes: 38 additions & 0 deletions test/test-golden/v2020-12-simple.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,22 @@ Image data used to create a texture. Image **MAY** be referenced by an URI (or I

|===

.`Image` Pattern Properties
|===
| |Type|Description|Required

|**`/^(?:rgb\|hex\|hsl\|rgba\|hsla)Color/`**
|`string`
|The background color for the image
|No

|**`/^(?:height\|width)$/`**
|`string`
|A dimension for the image
|No

|===

Additional properties are allowed.

=== Image.uri
Expand Down Expand Up @@ -93,6 +109,28 @@ An array of three fractional numbers.
** `[18, 0.1, 1.1]`


=== Image.`/^(?:rgb\|hex\|hsl\|rgba\|hsla)Color/`

The background color for the image

* **Type**: `string`
* **Required**: No
* **Examples**:
** `"rgb(255, 99, 71)"`
** `"#ff6347"`
** `"hsl(9, 100%, 64%)"`

=== Image.`/^(?:height\|width)$/`

A dimension for the image

* **Type**: `string`
* **Required**: No
* **Examples**:
** `"10"`
** `"400px"`


== Examples

* `{"uri": "https://raw.githubusercontent.com/KhronosGroup/glTF/main/specification/figures/gltf.png", "mimeType": "image/png"}`
Expand Down
29 changes: 29 additions & 0 deletions test/test-golden/v2020-12-simple.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,13 @@ Image data used to create a texture. Image **MAY** be referenced by an URI (or I
|**fraction**|`number`|A number that **MUST** be between zero and one.|No|
|**moreFractions**|`number` `[3]`|An array of three fractional numbers.|No, default: `[0.1,0.2,0.3]`|

**`Image` Pattern Properties**

| |Type|Description|Required|
|---|---|---|---|
|**`/^(?:rgb\|hex\|hsl\|rgba\|hsla)Color/`**|`string`|The background color for the image|No|
|**`/^(?:height\|width)$/`**|`string`|A dimension for the image|No|

Additional properties are allowed.

### Image.uri
Expand Down Expand Up @@ -72,6 +79,28 @@ An array of three fractional numbers.
* `[18, 0.1, 1.1]`


### Image.`/^(?:rgb\|hex\|hsl\|rgba\|hsla)Color/`

The background color for the image

* **Type**: `string`
* **Required**: No
* **Examples**:
* `"rgb(255, 99, 71)"`
* `"#ff6347"`
* `"hsl(9, 100%, 64%)"`

### Image.`/^(?:height\|width)$/`

A dimension for the image

* **Type**: `string`
* **Required**: No
* **Examples**:
* `"10"`
* `"400px"`


## Examples

* `{"uri": "https://raw.githubusercontent.com/KhronosGroup/glTF/main/specification/figures/gltf.png", "mimeType": "image/png"}`
Expand Down
Loading

0 comments on commit fb4db4a

Please sign in to comment.