File tree 3 files changed +35
-12
lines changed 3 files changed +35
-12
lines changed Original file line number Diff line number Diff line change @@ -20,9 +20,7 @@ def convert_outline(node, opts = {})
20
20
def convert_outline_section ( section , toclevels )
21
21
return if section . roles . include? 'exclude'
22
22
23
- title = section . attr 'titleabbrev'
24
- title ||= section . title
25
- link = %(<a href="##{ section . id } ">#{ title } </a>)
23
+ link = %(<a href="##{ section . id } ">#{ section_link_text section } </a>)
26
24
link = %(<span class="#{ wrapper_class_for section } ">#{ link } </span>)
27
25
[
28
26
%(<li>#{ link } ) ,
@@ -31,6 +29,14 @@ def convert_outline_section(section, toclevels)
31
29
] . compact
32
30
end
33
31
32
+ def section_link_text ( section )
33
+ text = section . xreftext nil
34
+ # Normally we won't get an <em> wrapping the text *but* if it was set
35
+ # with something like `reftext=_title_` to make it render properly in
36
+ # in most places then it will have the <em> and we have to remove it.
37
+ text . gsub %r{^<em>(.+)</em>$} , '\\1'
38
+ end
39
+
34
40
def convert_outline_subsections ( section , toclevels )
35
41
return unless section . level < toclevels && section . sections?
36
42
Original file line number Diff line number Diff line change @@ -7,7 +7,7 @@ module DocbookCompat
7
7
# Looks for pass blocks with `<titleabbrev>` and adds an attributes to their
8
8
# parent section. This attribute is an abbreviated title used when rendering
9
9
# the table of contents. This exists entirely for backwards compatibility with
10
- # docbook. It is simpler and recommended to set the `titleabbrev ` attribute
10
+ # docbook. It is simpler and recommended to set the `reftext ` attribute
11
11
# directly on the section when the document is built with `--direct_html`.
12
12
class TitleabbrevHandler < TreeProcessorScaffold
13
13
def process_block ( block )
@@ -22,10 +22,17 @@ def process_pass(block)
22
22
23
23
text . slice! m . begin ( 0 ) , m . end ( 0 )
24
24
block . lines = text . split "\n "
25
+ process_titleabbrev block , m [ 1 ]
26
+ end
27
+
28
+ private
25
29
30
+ def process_titleabbrev ( block , reftext )
26
31
section = block . parent
27
32
section = section . parent until section . context == :section
28
- section . attributes [ 'titleabbrev' ] = m [ 1 ]
33
+ # Docbook seems to bold links to sections less than 2 so we should too.
34
+ reftext = "_#{ reftext } _" if section . level < 2
35
+ section . attributes [ 'reftext' ] = reftext
29
36
end
30
37
end
31
38
end
Original file line number Diff line number Diff line change 240
240
end
241
241
end
242
242
end
243
- context 'when a section has a titleabbrev ' do
243
+ context 'when a section has reftext ' do
244
244
let ( :convert_attributes ) do
245
245
{
246
246
# Shrink the output slightly so it is easier to read
253
253
'toclevels' => 2 ,
254
254
}
255
255
end
256
- shared_examples 'titleabbrev ' do
256
+ shared_examples 'reftext ' do
257
257
context 'the table of contents' do
258
258
it 'includes the abbreviated title' do
259
259
expect ( converted ) . to include <<~HTML
260
- < li > < span class ="chapter "> < a href ="#_section_1 "> S1</ a > </ span >
260
+ < li > < span class ="chapter "> < a href ="#s1 "> S1</ a > </ span >
261
261
HTML
262
262
end
263
263
it 'includes the correct title for a subsection' do
273
273
it 'includes the unabbreviated title' do
274
274
expect ( converted ) . to include 'Section 1</h1>'
275
275
end
276
+ it 'includes a link to the abbreviated section' do
277
+ expect ( converted ) . to include <<~HTML . strip
278
+ < a class ="xref " href ="#s1 "title ="Section 1 "> < em > S1</ em > </ a >
279
+ HTML
280
+ end
276
281
end
277
282
end
278
- context 'using a pass block' do
283
+ context 'using a pass block containing titleabbrev ' do
279
284
let ( :input ) do
280
285
<<~ASCIIDOC
281
286
= Title
282
287
288
+ [[s1]]
283
289
== Section 1
284
290
++++
285
291
<titleabbrev>S1</titleabbrev>
286
292
++++
287
293
288
294
=== Section 2
295
+
296
+ <<s1>>
289
297
ASCIIDOC
290
298
end
291
- include_examples 'titleabbrev '
299
+ include_examples 'reftext '
292
300
end
293
301
context 'using an attribute' do
294
302
let ( :input ) do
295
303
<<~ASCIIDOC
296
304
= Title
297
305
298
- [titleabbrev=S1 ]
306
+ [id=s1,reftext=_S1_ ]
299
307
== Section 1
300
308
301
309
=== Section 2
310
+
311
+ <<s1>>
302
312
ASCIIDOC
303
313
end
304
- include_examples 'titleabbrev '
314
+ include_examples 'reftext '
305
315
end
306
316
end
307
317
end
You can’t perform that action at this time.
0 commit comments