Skip to content

Commit

Permalink
Merge pull request #38 from blocknotes/fix-duplicated-before-content
Browse files Browse the repository at this point in the history
Send the `li` before content only once
  • Loading branch information
blocknotes authored May 3, 2022
2 parents ffc1dd2 + 8d3bb21 commit 81c7b2d
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 3 deletions.
2 changes: 1 addition & 1 deletion examples/random_content.html
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ <h1>Random content <small>(with various elements and styles)</small></h1>
Li 2
<ol>
<li>Li 2 - 1</li>
<li>Li 2 - 2</li>
<li>Text that is <b>bold</b> and <i>italic</i> also.</li>
<li>Li 2 - 3</li>
</ol>
</li>
Expand Down
Binary file modified examples/random_content.pdf
Binary file not shown.
3 changes: 2 additions & 1 deletion lib/prawn_html/document_renderer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,8 @@ def apply_tag_open_styles(element)
end

def prepare_text(content)
text = context.before_content ? ::Oga::HTML::Entities.decode(context.before_content) : ''
before_content = context.before_content
text = before_content ? ::Oga::HTML::Entities.decode(before_content) : ''
return (@last_text = text + content) if context.white_space_pre?

content = content.lstrip if @last_text[-1] == ' ' || @last_tag_open
Expand Down
4 changes: 3 additions & 1 deletion lib/prawn_html/tags/li.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ def block?
end

def before_content
@counter ? "#{@counter}. " : "#{@symbol} "
return if @before_content_once

@before_content_once = @counter ? "#{@counter}. " : "#{@symbol} "
end

def block_styles
Expand Down

0 comments on commit 81c7b2d

Please sign in to comment.