Skip to content

Commit

Permalink
Merge pull request #219 from jelovirt/feature/refactor-html-xslt
Browse files Browse the repository at this point in the history
Remove commented support for data-hd-class
  • Loading branch information
jelovirt authored Apr 20, 2024
2 parents c406cdc + 76f5e62 commit 831acd4
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 87 deletions.
86 changes: 9 additions & 77 deletions src/main/resources/hdita2dita-common.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,7 @@
</xsl:template>

<xsl:template match="article">
<xsl:variable name="name" select="(:if (@data-hd-class) then @data-hd-class else :)'topic'"/>
<xsl:element name="{$name}">
<topic>
<xsl:apply-templates select="." mode="class"/>
<xsl:apply-templates select="." mode="topic"/>
<xsl:apply-templates select="ancestor::*/@xml:lang"/>
Expand Down Expand Up @@ -70,9 +69,12 @@
</body>
<!--/xsl:if-->
<xsl:apply-templates select="article"/>
</xsl:element>
</topic>
</xsl:template>

<xsl:template match="article" mode="class">
<xsl:attribute name="class">- topic/topic </xsl:attribute>
</xsl:template>

<xsl:function name="x:get-id" as="attribute()?">
<xsl:param name="topic" as="element()"/>
<xsl:variable name="title" select="($topic/h1 | $topic/h2 | $topic/h3 | $topic/h4 | $topic/h5 | $topic/h6)[1]" as="element()?"/>
Expand All @@ -81,75 +83,23 @@
</xsl:if>
</xsl:function>

<xsl:template match="article" mode="class">
<xsl:attribute name="class">
<xsl:text>- topic/topic </xsl:text>
<!--
<xsl:if test="@data-hd-class">
<xsl:value-of select="concat(@data-hd-class, '/', @data-hd-class, ' ')"/>
</xsl:if>
-->
</xsl:attribute>
</xsl:template>
<!--
<xsl:template match="article[@data-hd-class = 'concept']" mode="class">
<xsl:attribute name="class">- topic/topic concept/concept </xsl:attribute>
</xsl:template>
<xsl:template match="article[@data-hd-class = 'task']" mode="class">
<xsl:attribute name="class">- topic/topic task/task </xsl:attribute>
</xsl:template>
<xsl:template match="article[@data-hd-class = 'reference']" mode="class">
<xsl:attribute name="class">- topic/topic reference/reference </xsl:attribute>
</xsl:template>
-->

<xsl:template match="*" mode="topic">
<xsl:attribute name="ditaarch:DITAArchVersion">2.0</xsl:attribute>
<xsl:attribute name="specializations">@props/audience @props/deliveryTarget @props/otherprops @props/platform @props/product</xsl:attribute>
</xsl:template>
<!--
<xsl:template match="article[@data-hd-class = 'concept']" mode="topic">
<xsl:attribute name="domains">(topic abbrev-d) a(props deliveryTarget) (topic equation-d) (topic hazard-d) (topic hi-d) (topic indexing-d) (topic markup-d) (topic mathml-d) (topic pr-d) (topic relmgmt-d) (topic sw-d) (topic svg-d) (topic ui-d) (topic ut-d) (topic markup-d xml-d)</xsl:attribute>
</xsl:template>
<xsl:template match="article[@data-hd-class = 'task']" mode="topic">
<xsl:attribute name="domains">(topic concept) (topic abbrev-d) a(props deliveryTarget) (topic equation-d) (topic hazard-d) (topic hi-d) (topic indexing-d) (topic markup-d) (topic mathml-d) (topic pr-d) (topic relmgmt-d) (topic sw-d) (topic svg-d) (topic ui-d) (topic ut-d) (topic markup-d xml-d)</xsl:attribute>
</xsl:template>
<xsl:template match="article[@data-hd-class = 'reference']" mode="topic">
<xsl:attribute name="domains">(topic reference) (topic abbrev-d) a(props deliveryTarget) (topic equation-d) (topic hazard-d) (topic hi-d) (topic indexing-d) (topic markup-d) (topic mathml-d) (topic pr-d) (topic relmgmt-d) (topic sw-d) (topic svg-d) (topic ui-d) (topic ut-d) (topic markup-d xml-d)</xsl:attribute>
</xsl:template>
-->

<xsl:template match="section">
<xsl:variable name="name" select="(:if (@data-hd-class = 'topic/example') then 'example' else :)'section'"/>
<xsl:element name="{$name}">
<section>
<xsl:apply-templates select="." mode="class"/>
<xsl:apply-templates select="@*"/>
<xsl:if test="empty(@id)">
<xsl:sequence select="x:get-id(.)"/>
</xsl:if>
<xsl:apply-templates select="*"/>
</xsl:element>
</section>
</xsl:template>
<xsl:template match="section" mode="class">
<xsl:attribute name="class">
<!--
<xsl:choose>
<xsl:when test="@data-hd-class = 'topic/example'">
<xsl:text>- topic/example </xsl:text>
</xsl:when>
<xsl:when test="contains(@data-hd-class, '/')">
<xsl:text>- topic/section </xsl:text>
<xsl:value-of select="concat(@data-hd-class, '/', @data-hd-class)"/>
<xsl:text> </xsl:text>
</xsl:when>
<xsl:otherwise>
-->
<xsl:text>- topic/section </xsl:text>
<!--
</xsl:otherwise>
</xsl:choose>
-->
</xsl:attribute>
<xsl:attribute name="class">- topic/section </xsl:attribute>
</xsl:template>

<xsl:template match="h1 | h2">
Expand Down Expand Up @@ -446,12 +396,6 @@
<!-- Ignore this attribute -->
</xsl:template>

<!--
<xsl:template match="*[@data-hd-class = 'topic/example']" mode="class">
<xsl:attribute name="class">- topic/example </xsl:attribute>
</xsl:template>
-->

<xsl:template match="br">
<xsl:processing-instruction name="linebreak"/>
</xsl:template>
Expand Down Expand Up @@ -715,16 +659,6 @@
<xsl:attribute name="props" select="."/>
</xsl:template>

<!--
<xsl:template match="*[@data-hd-class]" mode="class" priority="-5">
<xsl:attribute name="class">
<xsl:text>- </xsl:text>
<xsl:value-of select="@data-hd-class"/>
<xsl:text> </xsl:text>
</xsl:attribute>
</xsl:template>
-->

<xsl:variable name="classes" as="map(*)">
<xsl:map>
<xsl:map-entry key="'ditavalmeta'" select="'+ map/topicmeta ditavalref-d/ditavalmeta '"/>
Expand Down Expand Up @@ -1434,8 +1368,6 @@
</xsl:copy>
</xsl:template>

<xsl:template match="@data-hd-class" priority="10"/>

<xsl:template match="@data-keyref">
<xsl:attribute name="keyref" select="."/>
</xsl:template>
Expand Down
2 changes: 0 additions & 2 deletions src/main/resources/hdita2dita-markdown.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,4 @@
<xsl:attribute name="{substring-after(name(), '-')}" select="."/>
</xsl:template>

<xsl:template match="@data-hd-class" priority="10"/>

</xsl:stylesheet>
8 changes: 4 additions & 4 deletions src/test/resources/hdita/hdita.html
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
<!DOCTYPE html>
<meta charset="utf-8">
<article data-hd-class="task">
<article>
<h1 id="how-to-do-something">How to do something</h1>
<p>Introduction to this specific task</p>
<section data-hd-class="task/context">
<section>
<p>Use only when ready</p>
</section>
<section data-hd-class="task/steps-informal">
<section>
<ol>
<li><p>Plan something</p></li>
<li><p>Do something</p></li>
<li><p>Evaluate something</p></li>
</ol>
</section>
<section data-hd-class="topic/example">
<section>
<p>Like this</p>
</section>
</article>
8 changes: 4 additions & 4 deletions src/test/resources/html/hdita.html
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
<!DOCTYPE html>
<meta charset="utf-8">
<article data-hd-class="task">
<article>
<h1 id="how-to-do-something">How to do something</h1>
<p>Introduction to this specific task</p>
<section data-hd-class="task/context">
<section>
<p>Use only when ready</p>
</section>
<section data-hd-class="task/steps-informal">
<section>
<ol>
<li><p>Plan something</p></li>
<li><p>Do something</p></li>
<li><p>Evaluate something</p></li>
</ol>
</section>
<section data-hd-class="topic/example">
<section>
<p>Like this</p>
</section>
</article>

0 comments on commit 831acd4

Please sign in to comment.