Skip to content

Commit 1a941c2

Browse files
author
Sanders Kleinfeld
committed
Merge pull request #136 from oreillymedia/labels
Proper labeling for formal elements nested in parts
2 parents 768c0a4 + 74bfab5 commit 1a941c2

File tree

4 files changed

+119
-13
lines changed

4 files changed

+119
-13
lines changed

htmlbook-xsl/common.xsl

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,9 +143,10 @@
143143
</xsl:template>
144144

145145
<xsl:template match="h:figure" mode="label.markup">
146+
<xsl:param name="label.formal.with.ancestor" select="$label.formal.with.ancestor"/>
146147
<xsl:choose>
147148
<xsl:when test="$label.formal.with.ancestor != 0">
148-
<xsl:apply-templates select="ancestor::h:section[contains(@data-type, 'acknowledgments') or
149+
<xsl:apply-templates select="(ancestor::h:section[contains(@data-type, 'acknowledgments') or
149150
contains(@data-type, 'afterword') or
150151
contains(@data-type, 'appendix') or
151152
contains(@data-type, 'bibliography') or
@@ -161,7 +162,8 @@
161162
contains(@data-type, 'introduction') or
162163
contains(@data-type, 'preface') or
163164
contains(@data-type, 'titlepage') or
164-
contains(@data-type, 'toc')][last()]" mode="label.markup"/>
165+
contains(@data-type, 'toc')]|
166+
ancestor::h:div[@data-type = 'part'])[last()]" mode="label.markup"/>
165167
<xsl:apply-templates select="." mode="intralabel.punctuation"/>
166168
<xsl:number count="h:figure[not(contains(@data-type, 'cover'))]" from="h:section[contains(@data-type, 'acknowledgments') or
167169
contains(@data-type, 'afterword') or

htmlbook-xsl/xspec/chunk.xspec

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -429,6 +429,32 @@
429429

430430
</x:scenario>
431431

432+
<x:scenario label="If callout-type 'stealth XREF' 'a' elements are matched">
433+
<x:context select="(//h:a[@class='co'])[1]">
434+
<pre data-type="programlisting" data-code-language="json"><?db-font-size 65%?>{
435+
"context_is_admin": [["role:admin"]],
436+
"admin_or_owner": [["is_admin:True"], ["project_id:%(project_id)s"]], <a class="co" id="co_ch9-co-1" href="#callout_ch9-co-1"><img src="/usr/local/app/git_tmp/c3c6787bcdd5a68b82f8e9e0a5dd141c/doc/openstack-ops/callouts/1.png" alt="1"/></a>
437+
...
438+
</pre>
439+
</x:context>
440+
441+
<x:scenario label="with url.in.parens disabled (callout stealth XREF; XREF with no data-type)">
442+
<x:context>
443+
<x:param name="url.in.parens" select="0"/>
444+
</x:context>
445+
446+
<x:expect label="No URL should be generated in parentheses after the 'a'" test="not(exists(//h:span[@class='print_url_in_parens']))"/>
447+
</x:scenario>
448+
449+
<x:scenario label="with url.in.parens enabled (callout stealth XREF; XREF with no data-type)">
450+
<x:context>
451+
<x:param name="url.in.parens" select="1"/>
452+
</x:context>
453+
454+
<x:expect label="No URL should be generated in parentheses after the 'a'" test="not(exists(//h:span[@class='print_url_in_parens']))"/>
455+
</x:scenario>
456+
</x:scenario>
457+
432458
<x:pending>
433459
<!-- Make sure there are some href tests with XREFs that are intra-chunk -->
434460
<!-- Possible to get this block working within XSpec? Currently getting the right results when

htmlbook-xsl/xspec/common.xspec

Lines changed: 63 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -183,33 +183,85 @@ sect5:none
183183
<x:expect label="The appropriate numeration value should be generated (absolute, not relative to part)">3</x:expect>
184184
</x:scenario>
185185

186-
<x:pending>
187-
188-
<x:scenario label="When generating a label for a part div with label.section.with.ancestors enabled">
189-
<x:context>
186+
<x:scenario label="When generating a label for a figure in a chapter-level division">
187+
<x:context select="(//h:section//h:figure)[2]" mode="label.markup">
188+
<section data-type="chapter">
189+
<h1>This is a chapter heading</h1>
190+
<p>Running out of amusing things to say</p>
191+
<figure>
192+
<img src="tokyo.png"/>
193+
<figcaption>A picture of the Tokyo skyline</figcaption>
194+
</figure>
195+
196+
<figure>
197+
<img src="paris.png"/>
198+
<figcaption>A picture of the Paris skyline</figcaption>
199+
</figure>
200+
</section>
190201
</x:context>
191-
<x:expect label="The appropriate numeration value should be generated"/>
202+
203+
<x:scenario label="With label.formal.with.ancestor disabled">
204+
<x:context>
205+
<x:param name="label.formal.with.ancestor" select="0"/>
206+
</x:context>
207+
<x:expect label="The appropriate numeration value should be generated">2</x:expect>
208+
</x:scenario>
209+
210+
<x:scenario label="With label.formal.with.ancestor enabled">
211+
<x:context>
212+
<x:param name="label.formal.with.ancestor" select="1"/>
213+
</x:context>
214+
<x:expect label="The appropriate numeration value should be generated">1-2</x:expect>
215+
</x:scenario>
192216
</x:scenario>
193217

194-
<x:scenario label="When generating a label for a section (chapter) with label.section.with.ancestors enabled">
195-
<x:context>
218+
<x:scenario label="When generating a label for a figure in a Part">
219+
<x:context select="(//h:div[@data-type='part']//h:figure)[2]" mode="label.markup">
220+
<div data-type="part">
221+
<h1>This is a Part heading</h1>
222+
<p>More text here</p>
223+
<figure>
224+
<img src="barcelona.png"/>
225+
<figcaption>A picture of the Barcelona skyline</figcaption>
226+
</figure>
227+
228+
<figure>
229+
<img src="quito.png"/>
230+
<figcaption>A picture of the Quito skyline</figcaption>
231+
</figure>
232+
</div>
196233
</x:context>
197-
<x:expect label="The appropriate numeration value should be generated"/>
234+
235+
<x:scenario label="With label.formal.with.ancestor disabled">
236+
<x:context>
237+
<x:param name="label.formal.with.ancestor" select="0"/>
238+
</x:context>
239+
<x:expect label="The appropriate numeration value should be generated">2</x:expect>
240+
</x:scenario>
241+
242+
<x:scenario label="With label.formal.with.ancestor enabled">
243+
<x:context>
244+
<x:param name="label.formal.with.ancestor" select="1"/>
245+
</x:context>
246+
<x:expect label="The appropriate numeration value should be generated">I-2</x:expect>
247+
</x:scenario>
198248
</x:scenario>
199249

200-
<x:scenario label="When generating a label for a section (subsection) with label.section.with.ancestors enabled">
250+
<x:pending>
251+
252+
<x:scenario label="When generating a label for a part div with label.section.with.ancestors enabled">
201253
<x:context>
202254
</x:context>
203255
<x:expect label="The appropriate numeration value should be generated"/>
204256
</x:scenario>
205257

206-
<x:scenario label="When generating a label for a figure">
258+
<x:scenario label="When generating a label for a section (chapter) with label.section.with.ancestors enabled">
207259
<x:context>
208260
</x:context>
209261
<x:expect label="The appropriate numeration value should be generated"/>
210262
</x:scenario>
211263

212-
<x:scenario label="When generating a label for a figure (label.formal.with.ancestor = false)">
264+
<x:scenario label="When generating a label for a section (subsection) with label.section.with.ancestors enabled">
213265
<x:context>
214266
</x:context>
215267
<x:expect label="The appropriate numeration value should be generated"/>

htmlbook-xsl/xspec/xrefgen.xspec

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -827,6 +827,32 @@
827827

828828
</x:scenario>
829829

830+
<x:scenario label="If callout-type 'stealth XREF' 'a' elements are matched">
831+
<x:context select="(//h:a[@class='co'])[1]">
832+
<pre data-type="programlisting" data-code-language="json"><?db-font-size 65%?>{
833+
"context_is_admin": [["role:admin"]],
834+
"admin_or_owner": [["is_admin:True"], ["project_id:%(project_id)s"]], <a class="co" id="co_ch9-co-1" href="#callout_ch9-co-1"><img src="/usr/local/app/git_tmp/c3c6787bcdd5a68b82f8e9e0a5dd141c/doc/openstack-ops/callouts/1.png" alt="1"/></a>
835+
...
836+
</pre>
837+
</x:context>
838+
839+
<x:scenario label="with url.in.parens disabled (callout stealth XREF; XREF with no data-type)">
840+
<x:context>
841+
<x:param name="url.in.parens" select="0"/>
842+
</x:context>
843+
844+
<x:expect label="No URL should be generated in parentheses after the 'a'" test="not(exists(//h:span[@class='print_url_in_parens']))"/>
845+
</x:scenario>
846+
847+
<x:scenario label="with url.in.parens enabled (callout stealth XREF; XREF with no data-type)">
848+
<x:context>
849+
<x:param name="url.in.parens" select="1"/>
850+
</x:context>
851+
852+
<x:expect label="No URL should be generated in parentheses after the 'a'" test="not(exists(//h:span[@class='print_url_in_parens']))"/>
853+
</x:scenario>
854+
</x:scenario>
855+
830856
<!-- Tests for whether an HREF is considered to be an XREF (link within the same corpus) -->
831857
<x:scenario label="If an href starts with a '#'">
832858
<x:call template="href-is-xref">

0 commit comments

Comments
 (0)