Skip to content

Commit

Permalink
resolves asciidoctor#2034 only indent paragraph that follows an adjac…
Browse files Browse the repository at this point in the history
…ent paragraph if prose-adjacent-text-indent key is set in theme
  • Loading branch information
mojavelinux committed Apr 18, 2022
1 parent a65c718 commit ed73c20
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ Enhancements::
* log error and skip table instead of raising error if cell content cannot fit into column width of table (#2009)
* extract `arrange_section` method to compute whether section title should be advanced to next page (#2023)
* introduce `callout-list` category in theme to control font properties and item spacing of callout lists (#1722)
* only indent inner paragraphs (paragraphs that follow an adjacent paragraph) if `prose-inner-text-indent` key is set in theme (#2034)

Bug Fixes::

Expand Down
7 changes: 7 additions & 0 deletions docs/theming-guide.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -2371,10 +2371,17 @@ The bottom margin is only added if the block is followed by an adjacent block wi
(default: _not set_)
|prose:
text-indent: 18

|inner-text-indent^[2]^
|<<measurement-units,Measurement>> +
(default: _not set_)
|prose:
inner-text-indent: 18
|===

1. Controls the margin between adjacent paragraphs.
Useful when using indented paragraphs.
2. Only applied to inner paragraphs (paragraphs that follow an adjacent paragraph).

[#keys-block]
=== Block
Expand Down
5 changes: 4 additions & 1 deletion lib/asciidoctor/pdf/converter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -460,6 +460,7 @@ def prepare_theme theme
theme.heading_margin_top ||= 0
theme.heading_margin_bottom ||= 0
theme.prose_text_indent ||= 0
theme.prose_inner_text_indent ||= 0
theme.prose_margin_bottom ||= 0
theme.block_margin_bottom ||= 0
theme.list_indent ||= 0
Expand Down Expand Up @@ -813,7 +814,9 @@ def convert_paragraph node
roles -= TextAlignmentRoles
end

if (text_indent = @theme.prose_text_indent) > 0
if (text_indent = @theme.prose_text_indent) > 0 ||
((text_indent = @theme.prose_inner_text_indent) > 0 &&
(self_idx = (siblings = node.parent.blocks).index node) > 0 && siblings[self_idx - 1].context == :paragraph)
prose_opts[:indent_paragraphs] = text_indent
end

Expand Down
26 changes: 26 additions & 0 deletions spec/paragraph_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,32 @@
(expect (pdf.text[3][:y] - list_item_text[:y]).round 2).to eql 27.78
end

it 'should indent first line of inner paragraphs if prose_inner_text_indent key is set in theme' do
left_margin = (to_pdf 'text', analyze: true).text[0][:x]
pdf_theme = {
prose_inner_text_indent: 10.5,
prose_margin_inner: 0,
}
pdf = to_pdf <<~EOS, analyze: true, pdf_theme: pdf_theme
#{lorem_ipsum '2-sentences-1-paragraph'}
#{lorem_ipsum '2-sentences-1-paragraph'}
> blockquote
#{lorem_ipsum '2-sentences-1-paragraph'}
#{lorem_ipsum '2-sentences-1-paragraph'}
EOS

lorem_texts = pdf.find_text %r/^Lorem/
(expect lorem_texts).to have_size 4
(expect lorem_texts[0][:x]).to eql left_margin
(expect lorem_texts[1][:x]).to be > left_margin
(expect lorem_texts[2][:x]).to eql left_margin
(expect lorem_texts[3][:x]).to be > left_margin
end

it 'should allow text alignment to be controlled using text-align document attribute' do
pdf = to_pdf <<~'EOS', analyze: true
= Document Title
Expand Down

0 comments on commit ed73c20

Please sign in to comment.