From ed73c202c34458d21b4b3ae042263c51b3a181de Mon Sep 17 00:00:00 2001 From: Dan Allen Date: Mon, 18 Apr 2022 14:53:25 -0600 Subject: [PATCH] resolves #2034 only indent paragraph that follows an adjacent paragraph if prose-adjacent-text-indent key is set in theme --- CHANGELOG.adoc | 1 + docs/theming-guide.adoc | 7 +++++++ lib/asciidoctor/pdf/converter.rb | 5 ++++- spec/paragraph_spec.rb | 26 ++++++++++++++++++++++++++ 4 files changed, 38 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.adoc b/CHANGELOG.adoc index 76dbea00e..db6828089 100644 --- a/CHANGELOG.adoc +++ b/CHANGELOG.adoc @@ -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:: diff --git a/docs/theming-guide.adoc b/docs/theming-guide.adoc index cbaa54e1a..353a73d05 100644 --- a/docs/theming-guide.adoc +++ b/docs/theming-guide.adoc @@ -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]^ +|<> + +(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 diff --git a/lib/asciidoctor/pdf/converter.rb b/lib/asciidoctor/pdf/converter.rb index 194a13d4a..01f484349 100644 --- a/lib/asciidoctor/pdf/converter.rb +++ b/lib/asciidoctor/pdf/converter.rb @@ -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 @@ -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 diff --git a/spec/paragraph_spec.rb b/spec/paragraph_spec.rb index 1b7d7558e..05ee38b8f 100644 --- a/spec/paragraph_spec.rb +++ b/spec/paragraph_spec.rb @@ -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