FIX: Inline error when converting html to markdown
Looks like some html elements like `aside` and `section` will throw an error when checking if they are inline or not. The commit simply handles ``` Job exception: undefined method `inline?' for nil:NilClass ``` and adds a test for it.
This commit is contained in:
parent
f683c5d0e0
commit
a89574ccb9
|
@ -99,7 +99,7 @@ class HtmlToMarkdown
|
|||
end
|
||||
|
||||
def is_inline?(node)
|
||||
node.text? || ("br" != node.name && node.description.inline? && node.children.all? { |n| is_inline?(n) })
|
||||
node.text? || ("br" != node.name && node.description&.inline? && node.children.all? { |n| is_inline?(n) })
|
||||
end
|
||||
|
||||
def collapse_spaces!(nodes, was_space = true)
|
||||
|
|
|
@ -65,6 +65,23 @@ describe HtmlToMarkdown do
|
|||
expect(html_to_markdown(html)).to eq(markdown.strip)
|
||||
end
|
||||
|
||||
it "doesn't error on non-inline elements like (aside, section)" do
|
||||
|
||||
html = <<~HTML
|
||||
<aside class="quote no-group">
|
||||
<blockquote>
|
||||
<p>hello.</p>
|
||||
</blockquote>
|
||||
</aside>
|
||||
HTML
|
||||
|
||||
markdown = <<~MD
|
||||
> hello.
|
||||
MD
|
||||
|
||||
expect(html_to_markdown(html)).to eq(markdown.strip)
|
||||
end
|
||||
|
||||
it "skips hidden tags" do
|
||||
expect(html_to_markdown(%Q{<p>Hello <span style="display: none">cruel </span>World!</p>})).to eq("Hello World!")
|
||||
expect(html_to_markdown(%Q{<p>Hello <span hidden>cruel </span>World!</p>})).to eq("Hello World!")
|
||||
|
|
Loading…
Reference in New Issue