Skip to content

Commit 140e6f9

Browse files
authored
Merge pull request ruby-docx#143 from ruby-docx/suppress-exceptions-from-internal-links-to_html
Suppress errors raised when calling to_html to docx with internal links
2 parents b928484 + c042502 commit 140e6f9

File tree

3 files changed

+14
-1
lines changed

3 files changed

+14
-1
lines changed

lib/docx/containers/text_run.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,11 @@ def underlined?
9595
end
9696

9797
def hyperlink?
98-
@node.name == 'hyperlink'
98+
@node.name == 'hyperlink' && external_link?
99+
end
100+
101+
def external_link?
102+
!@node.attributes['id'].nil?
99103
end
100104

101105
def href

spec/docx/document_spec.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -522,4 +522,13 @@
522522
end
523523
end
524524

525+
describe '#to_html' do
526+
before do
527+
@doc = Docx::Document.open(@fixtures_path + '/internal-links.docx')
528+
end
529+
530+
it 'should not raise error' do
531+
expect { @doc.to_html }.to_not raise_error
532+
end
533+
end
525534
end

spec/fixtures/internal-links.docx

9.62 KB
Binary file not shown.

0 commit comments

Comments
 (0)