Skip to content

Commit c9fb925

Browse files
committed
Ensure margins can be applied to specializatiodn
1 parent ad7fe18 commit c9fb925

1 file changed

Lines changed: 106 additions & 35 deletions

File tree

xsl/utility-classes.xsl

Lines changed: 106 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -630,7 +630,73 @@
630630
</xsl:template>
631631

632632
<!-- Process decorations (color, border, rounded, width) on any element -->
633-
<xsl:template match="*[@color or @border or @rounded or @width]" mode="get-output-class" priority="100">
633+
<!-- Process spacing and shadow decorations on any element -->
634+
<xsl:template match="*[@margin or @padding or @shadow]" mode="get-output-class" priority="-1">
635+
<xsl:variable
636+
name="margin"
637+
select="(@margin, (if (@shadow and @shadow != 'no' and @shadow != 'none' and not(contains(@outputclass, 'm-'))) then '3' else ()))[1]"
638+
/>
639+
<xsl:for-each select="tokenize(normalize-space($margin), '\s+')">
640+
<xsl:choose>
641+
<xsl:when test="matches(., '^[tbsxy]([0-5]|auto)$')">
642+
<xsl:value-of select="concat('m', substring(., 1, 1), '-', substring(., 2))"/>
643+
</xsl:when>
644+
<xsl:when test="matches(., '^e([0-5]|auto)$')">
645+
<xsl:value-of select="concat('me-', substring(., 2))"/>
646+
</xsl:when>
647+
<xsl:when test="contains(., '-')">
648+
<xsl:value-of select="."/>
649+
</xsl:when>
650+
<xsl:otherwise>
651+
<xsl:value-of select="concat('m-', .)"/>
652+
</xsl:otherwise>
653+
</xsl:choose>
654+
<xsl:text> </xsl:text>
655+
</xsl:for-each>
656+
<xsl:if
657+
test="@padding and not(contains(@class, ' topic/note ') or
658+
contains(@class, ' topic/pre ') or
659+
contains(@class, ' bootstrap-d/card ') or
660+
contains(@class, ' bootstrap-d/alert '))"
661+
>
662+
<xsl:for-each select="tokenize(normalize-space(@padding), '\s+')">
663+
<xsl:choose>
664+
<xsl:when test="matches(., '^[tbsxy]([0-5]|auto)$')">
665+
<xsl:value-of select="concat('p', substring(., 1, 1), '-', substring(., 2))"/>
666+
</xsl:when>
667+
<xsl:when test="matches(., '^e([0-5]|auto)$')">
668+
<xsl:value-of select="concat('pe-', substring(., 2))"/>
669+
</xsl:when>
670+
<xsl:when test="contains(., '-')">
671+
<xsl:value-of select="."/>
672+
</xsl:when>
673+
<xsl:otherwise>
674+
<xsl:value-of select="concat('p-', .)"/>
675+
</xsl:otherwise>
676+
</xsl:choose>
677+
<xsl:text> </xsl:text>
678+
</xsl:for-each>
679+
</xsl:if>
680+
<xsl:if test="@shadow">
681+
<xsl:choose>
682+
<xsl:when test="@shadow='yes'">
683+
<xsl:text>shadow </xsl:text>
684+
</xsl:when>
685+
<xsl:when test="@shadow='no' or @shadow='none'">
686+
<xsl:text>shadow-none </xsl:text>
687+
</xsl:when>
688+
<xsl:otherwise>
689+
<xsl:text>shadow-</xsl:text>
690+
<xsl:value-of select="@shadow"/>
691+
<xsl:text> </xsl:text>
692+
</xsl:otherwise>
693+
</xsl:choose>
694+
</xsl:if>
695+
<xsl:next-match/>
696+
</xsl:template>
697+
698+
<!-- Process decorations (color, border, rounded, width) on any element -->
699+
<xsl:template match="*[@color or @border or @rounded or @width]" mode="get-output-class" priority="-2">
634700
<xsl:if
635701
test="@color and not(contains(@class, ' topic/note ') or
636702
contains(@class, ' topic/pre ') or
@@ -675,40 +741,6 @@
675741
</xsl:otherwise>
676742
</xsl:choose>
677743
</xsl:if>
678-
<xsl:variable
679-
name="margin"
680-
select="(@margin, (if (@shadow and @shadow != 'no' and @shadow != 'none' and not(contains(@outputclass, 'm-'))) then '3' else ()))[1]"
681-
/>
682-
<xsl:if test="$margin">
683-
<xsl:text>m-</xsl:text>
684-
<xsl:value-of select="$margin"/>
685-
<xsl:text> </xsl:text>
686-
</xsl:if>
687-
<xsl:if
688-
test="@padding and not(contains(@class, ' topic/note ') or
689-
contains(@class, ' topic/pre ') or
690-
contains(@class, ' bootstrap-d/card ') or
691-
contains(@class, ' bootstrap-d/alert '))"
692-
>
693-
<xsl:text>p-</xsl:text>
694-
<xsl:value-of select="@padding"/>
695-
<xsl:text> </xsl:text>
696-
</xsl:if>
697-
<xsl:if test="@shadow">
698-
<xsl:choose>
699-
<xsl:when test="@shadow='yes'">
700-
<xsl:text>shadow </xsl:text>
701-
</xsl:when>
702-
<xsl:when test="@shadow='no' or @shadow='none'">
703-
<xsl:text>shadow-none </xsl:text>
704-
</xsl:when>
705-
<xsl:otherwise>
706-
<xsl:text>shadow-</xsl:text>
707-
<xsl:value-of select="@shadow"/>
708-
<xsl:text> </xsl:text>
709-
</xsl:otherwise>
710-
</xsl:choose>
711-
</xsl:if>
712744
<xsl:if test="@width">
713745
<xsl:text>w-</xsl:text>
714746
<xsl:value-of select="@width"/>
@@ -825,4 +857,43 @@
825857
</xsl:when>
826858
</xsl:choose>
827859
</xsl:template>
860+
861+
<!--
862+
The default set-output-class for a class of elements may be passed in with $default,
863+
but that default can be overridden with mode="get-output-class".
864+
In DITA Bootstrap we want these to be additive.
865+
-->
866+
<xsl:template match="*" mode="set-output-class" priority="10">
867+
<xsl:param name="default"/>
868+
<xsl:variable name="output-class">
869+
<xsl:apply-templates select="." mode="get-output-class"/>
870+
</xsl:variable>
871+
872+
<xsl:variable name="using-output-class" as="xs:string*">
873+
<xsl:value-of select="tokenize(normalize-space($output-class), '\s+')"/>
874+
<xsl:value-of select="tokenize(normalize-space($default), '\s+')"/>
875+
</xsl:variable>
876+
877+
<xsl:variable name="ancestry" as="xs:string?">
878+
<xsl:if test="$PRESERVE-DITA-CLASS = 'yes'">
879+
<xsl:value-of>
880+
<xsl:apply-templates select="." mode="get-element-ancestry"/>
881+
</xsl:value-of>
882+
</xsl:if>
883+
</xsl:variable>
884+
<xsl:variable name="outputclass-attribute" as="xs:string">
885+
<xsl:value-of>
886+
<xsl:apply-templates select="@outputclass" mode="get-value-for-class"/>
887+
</xsl:value-of>
888+
</xsl:variable>
889+
890+
<xsl:variable name="classes" as="xs:string*"
891+
select="tokenize($ancestry, '\s+'),
892+
$using-output-class,
893+
tokenize($outputclass-attribute, '\s+')"/>
894+
<xsl:if test="exists($classes)">
895+
<xsl:attribute name="class" select="distinct-values($classes)" separator=" "/>
896+
</xsl:if>
897+
</xsl:template>
898+
828899
</xsl:stylesheet>

0 commit comments

Comments
 (0)