Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generate anchors #362

Merged
merged 5 commits into from
Jun 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 20 additions & 5 deletions toolchains/xslt-M4/document/json/object-reference-html.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -58,15 +58,30 @@
<xsl:variable name="header-tag" select="if ($level le 6) then ('h' || $level) else 'p'"/>
<xsl:variable name="grouped-object" select="(self::array | self::singleton-or-array)/*"/>
<xsl:variable name="me" select="($grouped-object,.)[1]"/>

<div class="model-entry definition { tokenize($me/@_metaschema-json-id,'/')[2] }">
<xsl:variable name="header-class" expand-text="true">{ if (exists(parent::map)) then 'definition' else 'instance' }-header</xsl:variable>
<div class="{ $header-class }">
<!-- generates h1-hx headers picked up by Hugo toc -->
<xsl:element expand-text="true" name="{ $header-tag }" namespace="http://www.w3.org/1999/xhtml">
<xsl:attribute name="id" select="@_tree-json-id"/>
<xsl:attribute name="class">toc{ $level} name</xsl:attribute>
<xsl:text>{ @key }</xsl:text>
<!--
Generate the proper class attribute to match a given HTML header from $header-tag (h1, h2,...h6)
to define the proper corresponding style (toc1, toc2,... toc6) as bound by toc{ $level } in Hugo.

This build-time generation of anchor from template improves performance of website at load time
and decreases page "time to responsiveness" in the browser.
-->
<xsl:element name="a" namespace="http://www.w3.org/1999/xhtml">
<xsl:attribute name="href">#{@_tree-json-id}</xsl:attribute>
<xsl:attribute name="class">reference-element-anchor toc{$level} name </xsl:attribute>
<xsl:attribute name="title">Focus on {@key} details</xsl:attribute>

<xsl:element expand-text="true" name="{ $header-tag }" namespace="http://www.w3.org/1999/xhtml">
<xsl:attribute name="id" select="@_tree-json-id"/>
<xsl:attribute name="class">reference-element-anchor toc{$level} name </xsl:attribute>
<xsl:text>{ @key }</xsl:text>
</xsl:element>

</xsl:element>

<p class="type">
<xsl:apply-templates select="." mode="metaschema-type"/>
</p>
Expand Down
43 changes: 33 additions & 10 deletions toolchains/xslt-M4/document/xml/element-reference-html.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -49,19 +49,33 @@
<xsl:apply-templates/>
</div>
</xsl:template>

<!-- additional build-time generation of anchor from template to improve performance -->
<xsl:template match="*[exists(@gi)]" expand-text="true">
<xsl:variable name="level" select="count(ancestor-or-self::*[exists(@gi)])"/>
<xsl:variable name="header-tag" select="if ($level le 6) then ('h' || $level) else 'p'"/>
<div class="model-entry definition { tokenize(@_metaschema-xml-id,'/')[2] }">
<xsl:variable name="header-class" expand-text="true">{ if (exists(parent::map)) then 'definition' else 'instance' }-header</xsl:variable>
<div class="{ $header-class }">
<!-- generates h1-hx headers picked up by Hugo toc -->
<xsl:element expand-text="true" name="{ $header-tag }" namespace="http://www.w3.org/1999/xhtml">
<xsl:attribute name="id" select="@_tree-xml-id"/>
<xsl:attribute name="class">toc{ $level} name</xsl:attribute>
<xsl:text>{ @gi }</xsl:text>
<!--
Generate the proper class attribute to match a given HTML header from $header-tag (h1, h2,...h6)
to define the proper corresponding style (toc1, toc2,... toc6) as bound by toc{ $level } in Hugo.

This build-time generation of anchor from template improves performance of website at load time
to decrease page time to responsiveness in the browser.
-->
<xsl:element name="a" namespace="http://www.w3.org/1999/xhtml">
<xsl:attribute name="href">#{@_tree-xml-id}</xsl:attribute>
<xsl:attribute name="class">reference-element-anchor toc{ $level } name </xsl:attribute>
<xsl:attribute name="title">Focus on {@gi} details</xsl:attribute>

<xsl:element expand-text="true" name="{ $header-tag }" namespace="http://www.w3.org/1999/xhtml">
<xsl:attribute name="id" select="@_tree-xml-id"/>
<xsl:attribute name="class">reference-element-anchor toc{ $level} name</xsl:attribute>
<xsl:text>{ @gi }</xsl:text>
</xsl:element>

</xsl:element>

<!-- Only assign the @id here if there is a value and the type is not markup-multiline, since in the other cases it
is assigned to the header in the containing div -->
<p class="type">
Expand Down Expand Up @@ -124,10 +138,19 @@
<xsl:variable name="header-class" expand-text="true">{ if (exists(parent::map)) then 'definition' else 'instance' }-header</xsl:variable>
<div class="{ $header-class }">
<!-- generates h1-hx headers picked up by Hugo toc -->
<xsl:element expand-text="true" name="{ $header-tag }" namespace="http://www.w3.org/1999/xhtml">
<xsl:attribute name="id" select="@_tree-xml-id"/>
<xsl:attribute name="class">toc{ $level} name</xsl:attribute>
<xsl:text>(unwrapped)</xsl:text>

<!-- additional build-time generation of anchor from template to improve performance -->
<xsl:element expand-text="true" name="a" namespace="http://www.w3.org/1999/xhtml">
aj-stein-nist marked this conversation as resolved.
Show resolved Hide resolved
<xsl:attribute name="href">#{@_tree-xml-id}</xsl:attribute>
<xsl:attribute name="class">reference-element-anchor toc{ $level} name</xsl:attribute>
<xsl:attribute name="title">Get {@_tree-xml-id} details</xsl:attribute>

<!-- ===!!! The Headers 1-6 that are being wrapped around !!!=== -->
<xsl:element expand-text="true" name="{ $header-tag }" namespace="http://www.w3.org/1999/xhtml">
<xsl:attribute name="id" select="@_tree-xml-id" />
<xsl:attribute name="class">toc{ $level} name </xsl:attribute>
<xsl:text>(unwrapped) </xsl:text>
</xsl:element>
</xsl:element>
<p class="type">
<xsl:apply-templates select="." mode="metaschema-type"/>
Expand Down