Skip to content

Commit 9b8a391

Browse files
committed
allow role or theme to control text alignment of colist
1 parent cc39011 commit 9b8a391

File tree

4 files changed

+30
-2
lines changed

4 files changed

+30
-2
lines changed

CHANGELOG.adoc

+1
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ Enhancements::
3838
* set `chapter-numeral` attribute in running content on pages in chapter if `sectnums` attribute is set (#1373)
3939
* set `part-numeral` attribute in running content on pages in part if `partnums` attribute is set (#1373)
4040
* add support for normal_italic font style (to reset font style to normal, then apply italic) (#1603)
41+
* honor text alignment roles (e.g., `text-left`) or `list-text-align` theme key on callout lists
4142
* honor text alignment roles (e.g., `text-center`) on block image (#1609)
4243
* honor role and inherited role on inline image (#1939, #1376)
4344
* disable running header and/or footer on toc pages if `noheader` and/or `nofooter` option is set on toc macro (#1378)

lib/asciidoctor/pdf/converter.rb

+7-1
Original file line numberDiff line numberDiff line change
@@ -1112,9 +1112,15 @@ def convert_colist node
11121112
@list_numerals << 1
11131113
line_metrics = theme_font(:conum) { calc_line_metrics @base_line_height }
11141114
last_item = node.items[-1]
1115+
item_spacing = @theme.callout_list_item_spacing || @theme.list_item_spacing
1116+
item_opts = { margin_bottom: item_spacing, normalize_line_height: true }
1117+
if (item_align = (resolve_alignment_from_role node.roles) || @theme.list_text_align&.to_sym)
1118+
item_opts[:align] = item_align
1119+
end
11151120
node.items.each do |item|
11161121
allocate_space_for_list_item line_metrics
1117-
convert_colist_item item, margin_bottom: (item == last_item ? 0 : @theme.list_item_spacing), normalize_line_height: true
1122+
item_opts[:margin_bottom] = 0 if item == last_item
1123+
convert_colist_item item, item_opts
11181124
end
11191125
@list_numerals.pop
11201126
theme_margin :prose, :bottom, (next_enclosed_block node)

spec/list_spec.rb

+22-1
Original file line numberDiff line numberDiff line change
@@ -454,7 +454,7 @@
454454
end
455455

456456
it 'should allow text alignment to be set using theme', visual: true do
457-
to_file = to_pdf_file <<~EOS, 'list-text-left-role.pdf', pdf_theme: { list_text_align: 'left' }
457+
to_file = to_pdf_file <<~EOS, 'list-text-left-theme.pdf', pdf_theme: { list_text_align: 'left' }
458458
* #{lorem_ipsum '2-sentences-1-paragraph'}
459459
EOS
460460
(expect to_file).to visually_match 'list-text-left.pdf'
@@ -1983,6 +1983,27 @@
19831983
item_text = pdf.find_unique_text 'description'
19841984
(expect item_text[:page_number]).to be 2
19851985
end
1986+
1987+
it 'should allow text alignment to be set using role', visual: true do
1988+
to_file = to_pdf_file <<~EOS, 'colist-text-align-left-role.pdf'
1989+
----
1990+
data <1>
1991+
----
1992+
[.text-left]
1993+
<1> #{lorem_ipsum '2-sentences-1-paragraph'}
1994+
EOS
1995+
(expect to_file).to visually_match 'colist-text-align-left.pdf'
1996+
end
1997+
1998+
it 'should allow text alignment to be set using theme', visual: true do
1999+
to_file = to_pdf_file <<~EOS, 'colist-text-align-left-theme.pdf', pdf_theme: { list_text_align: 'left' }
2000+
----
2001+
data <1>
2002+
----
2003+
<1> #{lorem_ipsum '2-sentences-1-paragraph'}
2004+
EOS
2005+
(expect to_file).to visually_match 'colist-text-align-left.pdf'
2006+
end
19862007
end
19872008

19882009
context 'Bibliography' do
21 KB
Binary file not shown.

0 commit comments

Comments
 (0)