Skip to content

Commit

Permalink
Merge pull request #93 from diogoosorio/92-fix-list-paragraph-newlines
Browse files Browse the repository at this point in the history
Fixes unintentional newline characters within lists with paragraphs
  • Loading branch information
xijo authored Oct 31, 2021
2 parents c664cad + 3732a3b commit 2eab8dd
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 3 deletions.
4 changes: 2 additions & 2 deletions lib/reverse_markdown/converters/li.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ module ReverseMarkdown
module Converters
class Li < Base
def convert(node, state = {})
contains_child_paragraph = node.children.first ? node.children.first.name == 'p' : false
content_node = contains_child_paragraph ? node.children.first : node
contains_child_paragraph = node.first_element_child ? node.first_element_child.name == 'p' : false
content_node = contains_child_paragraph ? node.first_element_child : node
content = treat_children(content_node, state)
indentation = indentation_from(state)
prefix = prefix_for(node)
Expand Down
2 changes: 2 additions & 0 deletions spec/assets/lists.html
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@
</li>
</ul>

<ul><li> <p>I don't want to cleanup after the party!</p> </li></ul>

<ul>
<li>
<p>li 1, p 1</p>
Expand Down
3 changes: 2 additions & 1 deletion spec/components/lists_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@
end

context "lists containing embedded <p> tags" do
xit { is_expected.to match /\n- I want to have a party at my house!\n/ }
it { is_expected.to match /\n- I want to have a party at my house!\n/ }
it { is_expected.to match /\n- I don't want to cleanup after the party!\n/ }
end

context "list item containing multiple <p> tags" do
Expand Down

0 comments on commit 2eab8dd

Please sign in to comment.