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

RTL support #45

Merged
merged 17 commits into from
Sep 19, 2022
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
113 changes: 69 additions & 44 deletions Customization/xsl/nav.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -69,29 +69,29 @@
<xsl:value-of select="$pathFromMaplist"/>
</xsl:if>
<xsl:choose>
<xsl:when
<xsl:when
test="@copy-to and not(contains(@chunk, 'to-content')) and
(not(@format) or @format = 'dita' or @format = 'ditamap') "
>
<xsl:call-template name="replace-extension">
<xsl:with-param name="filename" select="@copy-to"/>
<xsl:with-param name="extension" select="$OUTEXT"/>
</xsl:call-template>
<xsl:if test="not(contains(@copy-to, '#')) and contains(@href, '#')">
<xsl:value-of select="concat('#', substring-after(@href, '#'))"/>
</xsl:if>
</xsl:when>
<xsl:when test="not(@scope = 'external') and (not(@format) or @format = 'dita' or @format = 'ditamap')">
<xsl:call-template name="replace-extension">
<xsl:with-param name="filename" select="@href"/>
<xsl:with-param name="extension" select="$OUTEXT"/>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="@href"/>
</xsl:otherwise>
</xsl:choose>
</xsl:attribute>
<xsl:call-template name="replace-extension">
<xsl:with-param name="filename" select="@copy-to"/>
<xsl:with-param name="extension" select="$OUTEXT"/>
</xsl:call-template>
<xsl:if test="not(contains(@copy-to, '#')) and contains(@href, '#')">
<xsl:value-of select="concat('#', substring-after(@href, '#'))"/>
</xsl:if>
</xsl:when>
<xsl:when test="not(@scope = 'external') and (not(@format) or @format = 'dita' or @format = 'ditamap')">
<xsl:call-template name="replace-extension">
<xsl:with-param name="filename" select="@href"/>
<xsl:with-param name="extension" select="$OUTEXT"/>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="@href"/>
</xsl:otherwise>
</xsl:choose>
</xsl:attribute>
</xsl:template>

<!-- Generate a menubar-toc - a menubar as part of the static header -->
Expand Down Expand Up @@ -120,7 +120,7 @@
<xsl:apply-templates select="$current-topicref" mode="list-group-toc-pull">
<xsl:with-param name="pathFromMaplist" select="$PATH2PROJ" as="xs:string"/>
<xsl:with-param name="children" as="element()*">
<xsl:apply-templates
<xsl:apply-templates
select="$current-topicref/*[contains(@class, ' map/topicref ')]"
mode="list-group-toc"
>
Expand Down Expand Up @@ -158,7 +158,7 @@
<xsl:apply-templates select="$current-topicref" mode="nav-pill-toc-pull">
<xsl:with-param name="pathFromMaplist" select="$PATH2PROJ" as="xs:string"/>
<xsl:with-param name="children" as="element()*">
<xsl:apply-templates
<xsl:apply-templates
select="$current-topicref/*[contains(@class, ' map/topicref ')]"
mode="nav-pill-toc"
>
Expand Down Expand Up @@ -187,7 +187,15 @@
</nav>
</xsl:when>
<xsl:when test="$nav-toc = ('collapsible')">
<!--xsl:variable name="direction">
<xsl:apply-templates select="." mode="get-render-direction">
<xsl:with-param name="lang" select="$defaultLanguage"/>
</xsl:apply-templates>
</xsl:variable-->
<nav role="navigation" id="bs-sidebar-nav" class="flex-column bd-links">
<xsl:if test="$BIDIRECTIONAL_DOCUMENT = 'yes'">
<xsl:attribute name="direction" select="$defaultDirection"/>
</xsl:if>
<ul class="list-unstyled mb-0 py-3 pt-md-1">
<xsl:apply-templates select="$input.map" mode="collapsible-toc">
<xsl:with-param name="pathFromMaplist" select="$PATH2PROJ" as="xs:string"/>
Expand Down Expand Up @@ -361,7 +369,9 @@
</xsl:variable>

<xsl:choose>
<xsl:when test="$BOOTSTRAP_MENUBAR_TOC = 'yes' and count(ancestor::*/@href) eq 0 and not($active-class = ' active')">
<xsl:when
test="$BOOTSTRAP_MENUBAR_TOC = 'yes' and count(ancestor::*/@href) eq 0 and not($active-class = ' active')"
>
<!-- no-op - if a menubar-toc is present, the list-group is reduced to current decendents only -->
</xsl:when>
<xsl:when test="normalize-space($title)">
Expand Down Expand Up @@ -401,10 +411,8 @@
</xsl:if>
</xsl:when>
</xsl:choose>

</xsl:template>


<!-- nav-pill-toc-pull mode to add Bootstrap nav-link classes to a sidebar -->
<xsl:template
match="*[contains(@class, ' map/topicref ')]
Expand Down Expand Up @@ -440,7 +448,7 @@
<xsl:with-param name="pathFromMaplist" select="$pathFromMaplist"/>
<xsl:with-param name="class">
<xsl:text>my-1 nav-link</xsl:text>
<xsl:value-of select="$active-class"/>
<xsl:value-of select="$active-class"/>
</xsl:with-param>
</xsl:call-template>
<xsl:value-of select="$title"/>
Expand Down Expand Up @@ -491,9 +499,10 @@
<xsl:call-template name="get-active-class"/>
</xsl:variable>


<xsl:choose>
<xsl:when test="$BOOTSTRAP_MENUBAR_TOC = 'yes' and count(ancestor::*/@href) eq 0 and not($active-class = ' active')">
<xsl:when
test="$BOOTSTRAP_MENUBAR_TOC = 'yes' and count(ancestor::*/@href) eq 0 and not($active-class = ' active')"
>
<!-- no-op - if a menubar-toc is present, the nav-bar is reduced to current decendents only -->
</xsl:when>
<xsl:when test="normalize-space($title)">
Expand Down Expand Up @@ -538,11 +547,7 @@
priority="10"
>
<xsl:param name="pathFromMaplist" as="xs:string"/>
<xsl:param
name="children"
select="*[contains(@class, ' map/topicref ')]"
as="element()*"
/>
<xsl:param name="children" select="*[contains(@class, ' map/topicref ')]" as="element()*"/>
<xsl:variable name="title">
<xsl:apply-templates select="." mode="get-navtitle"/>
</xsl:variable>
Expand Down Expand Up @@ -578,22 +583,32 @@
</xsl:attribute>
<xsl:attribute name="data-bs-target" select="concat('#menu-collapse-',$id)"/>
<xsl:if test="$show-menu='show'">
<xsl:attribute name="aria-expanded" select="'true'"/>
<xsl:attribute name="aria-current" select="'true'"/>
<xsl:attribute name="aria-expanded" select="'true'"/>
<xsl:attribute name="aria-current" select="'true'"/>
</xsl:if>
<xsl:attribute name="aria-labelledby" select="concat('menu-collapse-trigger-',$id)"/>
<xsl:attribute name="aria-controls" select="concat('menu-collapse-',$id)"/>
<svg xmlns='http://www.w3.org/2000/svg' width='20' height='16' viewBox='0 0 16 16'>
<path
fill='none'
stroke='currentColor'
stroke-linecap='round'
stroke-linejoin='round'
stroke-width='2'
d='M5 14l6-6-6-6'
/>
</svg>
</button>
</xsl:if>
<!-- ↓ Add Bootstrap classes to topic link ↓ -->
<a>
<xsl:call-template name="nav-attributes">
<xsl:with-param name="pathFromMaplist" select="$pathFromMaplist"/>
<xsl:with-param name="class">
<xsl:text>link-primary d-inline-flex align-items-center flex-shrink-1 </xsl:text>
<xsl:text>d-inline-flex align-items-center flex-shrink-1 </xsl:text>
<xsl:choose>
<xsl:when test="exists($children)">
<xsl:text>ps-0</xsl:text>
<xsl:text>ps-1</xsl:text>
</xsl:when>
<xsl:otherwise>
<xsl:text>ps-3</xsl:text>
Expand All @@ -608,7 +623,7 @@
</xsl:when>
<xsl:otherwise>
<!-- ↓ Add Toggle with title text ↓ -->
<div class ="d-flex flex-row">
<div class="d-flex flex-row">
<button data-bs-toggle="collapse">
<xsl:attribute name="class">
<xsl:text>btn d-inline-flex align-items-center pe-0</xsl:text>
Expand All @@ -618,21 +633,31 @@
</xsl:attribute>
<xsl:attribute name="data-bs-target" select="concat('#menu-collapse-',$id)"/>
<xsl:if test="$show-menu='show'">
<xsl:attribute name="aria-expanded" select="'true'"/>
<xsl:attribute name="aria-current" select="'true'"/>
<xsl:attribute name="aria-expanded" select="'true'"/>
<xsl:attribute name="aria-current" select="'true'"/>
</xsl:if>
<svg xmlns='http://www.w3.org/2000/svg' width='20' height='16' viewBox='0 0 16 16'>
<path
fill='none'
stroke='currentColor'
stroke-linecap='round'
stroke-linejoin='round'
stroke-width='2'
d='M5 14l6-6-6-6'
/>
</svg>
</button>
<span data-bs-toggle="collapse">
<xsl:attribute name="class">
<xsl:text>link-primary d-inline-flex align-items-center flex-shrink-1 ps0</xsl:text>
<xsl:text>d-inline-flex align-items-center flex-shrink-1 ps-1</xsl:text>
<xsl:if test="$show-menu='show'">
<xsl:text> active</xsl:text>
</xsl:if>
</xsl:attribute>
<xsl:attribute name="data-bs-target" select="concat('#menu-collapse-',$id)"/>
<xsl:if test="$show-menu='show'">
<xsl:attribute name="aria-expanded" select="'true'"/>
<xsl:attribute name="aria-current" select="'true'"/>
<xsl:attribute name="aria-expanded" select="'true'"/>
<xsl:attribute name="aria-current" select="'true'"/>
</xsl:if>
<xsl:value-of select="$title"/>
</span>
Expand All @@ -643,7 +668,7 @@
<div>
<xsl:attribute name="id" select="concat('menu-collapse-',$id)"/>
<xsl:attribute name="class" select="concat('collapse ', $show-menu)"/>
<ul class="list-unstyled fw-normal">
<ul class="list-unstyled fw-normal ps-4">
<xsl:apply-templates select="$children" mode="#current">
<xsl:with-param name="pathFromMaplist" select="$pathFromMaplist"/>
</xsl:apply-templates>
Expand Down
59 changes: 50 additions & 9 deletions Customization/xsl/topic.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,48 @@
exclude-result-prefixes="xs dita-ot dita2html"
>

<xsl:param name="defaultLanguage" select="'en'" as="xs:string"/>
<xsl:param name="BIDIRECTIONAL_DOCUMENT" select="'no'" as="xs:string"/>

<xsl:variable name="defaultDirection">
<xsl:apply-templates select="." mode="get-render-direction">
<xsl:with-param name="lang" select="$defaultLanguage"/>
</xsl:apply-templates>
</xsl:variable>


<!-- Define a newline character -->
<xsl:variable name="newline">
<xsl:text>
</xsl:text>
</xsl:variable>

<xsl:template name="chapter-setup">
<html>
<xsl:if test="$BIDIRECTIONAL_DOCUMENT = 'no'">
<xsl:call-template name="setTopicLanguage"/>
</xsl:if>
<xsl:if test="$BIDIRECTIONAL_DOCUMENT = 'yes'">
<xsl:attribute name="dir" select="$defaultDirection"/>
<xsl:attribute name="lang" select="$defaultLanguage"/>
</xsl:if>
<xsl:call-template name="chapterHead"/>
<xsl:call-template name="chapterBody"/>
</html>
</xsl:template>

<xsl:template match="*" mode="addContentToHtmlBodyElement">
<main xsl:use-attribute-sets="main">
<article xsl:use-attribute-sets="article">
<xsl:if test="$BIDIRECTIONAL_DOCUMENT = 'yes'">
<xsl:variable name="direction">
<xsl:apply-templates select="." mode="get-render-direction">
<xsl:with-param name="lang" select="dita-ot:get-current-language(.)"/>
</xsl:apply-templates>
</xsl:variable>
<xsl:attribute name="dir" select="$direction"/>
<xsl:attribute name="lang" select="dita-ot:get-current-language(.)"/>
</xsl:if>
<xsl:attribute name="aria-labelledby">
<xsl:apply-templates
select="*[contains(@class,' topic/title ')] |
Expand Down Expand Up @@ -49,8 +82,6 @@
</main>
</xsl:template>



<!-- Override to add Bootstrap classes and roles -->
<xsl:template name="commonattributes">
<xsl:param name="default-output-class"/>
Expand All @@ -60,6 +91,20 @@
<xsl:value-of select="$default-output-class"/>
</xsl:variable>
<xsl:call-template name="bootstrap-role"/>
<!-- ↓ Ensure code is rendered LTR in RTL documents ↓ -->
<xsl:if test="$BIDIRECTIONAL_DOCUMENT='true' and not(@dir)">
<xsl:choose>
<xsl:when test="contains(@class,' pr-d/')">
<xsl:attribute name="dir">auto</xsl:attribute>
</xsl:when>
<xsl:when test="contains(@class,' sw-d/')">
<xsl:attribute name="dir">auto</xsl:attribute>
</xsl:when>
<xsl:when test="contains(@class,' xml-d/')">
<xsl:attribute name="dir">auto</xsl:attribute>
</xsl:when>
</xsl:choose>
</xsl:if>
<!-- ↑ End customization · Continue with DITA-OT defaults ↓ -->
<xsl:apply-templates select="@xml:lang"/>
<xsl:apply-templates select="@dir"/>
Expand Down Expand Up @@ -189,8 +234,6 @@
<xsl:value-of select="$newline"/>
</xsl:template>



<!-- Figure caption -->
<xsl:template name="place-fig-lbl">
<xsl:param name="stringName"/>
Expand All @@ -210,13 +253,13 @@
<xsl:variable name="fig-caption-class">
<xsl:choose>
<xsl:when test="*[contains(@class, ' topic/lq ')]">
<xsl:value-of select="concat('blockquote-footer ', $BOOTSTRAP_CSS_FIGURE_CAPTION)"/>
<xsl:value-of select="concat('blockquote-footer ', $BOOTSTRAP_CSS_FIGURE_CAPTION)"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="concat('figure-caption ', $BOOTSTRAP_CSS_FIGURE_CAPTION)"/>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
</xsl:variable>
<xsl:apply-templates select="." mode="set-output-class">
<xsl:with-param
name="default"
Expand All @@ -225,7 +268,7 @@
</xsl:apply-templates>
<!-- ↑ End customization · Continue with DITA-OT defaults ↓ -->
<span class="fig--title-label">
<xsl:choose>
<xsl:choose>
<!-- Blockquote - figure -->
<xsl:when test="*[contains(@class, ' topic/lq ')]">
</xsl:when>
Expand Down Expand Up @@ -272,7 +315,6 @@
</xsl:choose>
</xsl:template>


<!-- Customization to add Bootstrap Borders to Codeblock elements-->
<!-- https://getbootstrap.com/docs/5.2/utilities/borders/ -->
<xsl:template match="*[contains(@class, ' topic/pre ') and @frame]">
Expand All @@ -298,7 +340,6 @@
</pre>
<xsl:apply-templates select="*[contains(@class, ' ditaot-d/ditaval-endprop ')]" mode="out-of-line"/>
</figure>

</xsl:template>

<!-- Customization to add Bootstrap Borders to Lines elements-->
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ For performance reasons, Bootstrap icons, popovers and tooltips are disabled by

- `icons.include` – enable Bootstrap icons
- `popovers.include` – enable Bootstrap popover components and tooltip components
- `bidi.include` - whether to include support for RTL languages

Breadcrumbs and menu bars can be added using the following parameters

Expand Down
Loading