Skip to content

Commit

Permalink
Link to HTML anchors, where they exist
Browse files Browse the repository at this point in the history
  • Loading branch information
richvdh committed Feb 14, 2024
1 parent 3736461 commit 3c52648
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions layouts/partials/openapi/render-object-table.html
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@
Computes the type to display for a property, given:

* `type`: string or array of strings for the type(s) of the property

* `title`: optional string for the title of the property

* `oneOf`: optional array of dictionaries describing the different formats
Expand All @@ -95,6 +95,9 @@

* `items`: if the type is an array, array of dictionaries describing the
format of the array's items

* `anchor`: optional HTML element id for the target type, which will be used to link to it.

*/}}
{{ define "partials/property-type" }}
{{ $type := .type }}
Expand Down Expand Up @@ -123,7 +126,7 @@
Computes the type to display for a property's schema, given:

* `type`: string or array of strings for the type(s) of the property

* `title`: optional string for the title of the property

* `oneOf`: optional array of dictionaries describing the different formats
Expand All @@ -134,7 +137,9 @@

* `patternProperties`: optional dictionary for properties with names
adhering to a regex pattern


* `anchor`: optional HTML element id for the target type, which will be used to link to it.

The title has a higher priority than anything else.
*/}}
{{ define "partials/type-or-title" }}
Expand All @@ -145,6 +150,9 @@
This means we can write things like `EventFilter` rather than `object`.
*/}}
{{ $type = .title }}
{{ if .anchor }}
{{ $type = printf "<a href=\"#%s\">%s</a>" (htmlEscape .anchor) (htmlEscape $type) | safeHTML }}
{{ end }}
{{ else if reflect.IsMap .additionalProperties }}
{{/*
If the property uses `additionalProperties` to describe its
Expand Down Expand Up @@ -205,9 +213,9 @@
* `property`: dictionary describing the property's data, with these fields:

* `description`: string describing the property

* `enum`: optional array indicating the accepted values for the property

* `x-addedInMatrixVersion`: optional string indicating in which Matrix
spec version this property was added.

Expand All @@ -220,4 +228,4 @@
{{ if .property.enum }}<p>One of: <code>[{{ delimit .property.enum ", " }}]</code>.</p>{{ end -}}
{{ if (index .property "x-addedInMatrixVersion") }}{{ partial "added-in" (dict "v" (index .property "x-addedInMatrixVersion")) }}{{ end -}}
{{ if (index .property "x-changedInMatrixVersion") }}{{ partial "changed-in" (dict "changes_dict" (index .property "x-changedInMatrixVersion")) }}{{ end -}}
{{ end }}
{{ end }}

0 comments on commit 3c52648

Please sign in to comment.