Skip to content

Commit

Permalink
Merge pull request #143 from ruby-docx/suppress-exceptions-from-inter…
Browse files Browse the repository at this point in the history
…nal-links-to_html

Suppress errors raised when calling to_html to docx with internal links
  • Loading branch information
satoryu committed Oct 29, 2023
2 parents b928484 + c042502 commit 140e6f9
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
6 changes: 5 additions & 1 deletion lib/docx/containers/text_run.rb
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,11 @@ def underlined?
end

def hyperlink?
@node.name == 'hyperlink'
@node.name == 'hyperlink' && external_link?
end

def external_link?
!@node.attributes['id'].nil?
end

def href
Expand Down
9 changes: 9 additions & 0 deletions spec/docx/document_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -522,4 +522,13 @@
end
end

describe '#to_html' do
before do
@doc = Docx::Document.open(@fixtures_path + '/internal-links.docx')
end

it 'should not raise error' do
expect { @doc.to_html }.to_not raise_error
end
end
end
Binary file added spec/fixtures/internal-links.docx
Binary file not shown.

0 comments on commit 140e6f9

Please sign in to comment.