Skip to content

Commit

Permalink
resolves #470 do not crash on an SVG image inside table cell (#473)
Browse files Browse the repository at this point in the history
closes #471
  • Loading branch information
slonopotamus committed May 12, 2024
1 parent 59bd130 commit 9d2cfc2
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ For a detailed view of what has changed, refer to the {uri-repo}/commits/master[
== Unreleased

* fix crash when section title contains inline anchor (#472)
* fix crash on an SVG image inside table cell (#470)

== 2.1.0 (2024-02-04) - @slonopotamus

Expand Down
11 changes: 10 additions & 1 deletion lib/asciidoctor-epub3/converter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,10 @@ def write(output, target)

EPUB_EXTENSION_RX = /\.epub$/i.freeze

# This is a workaround for https://github.com/asciidoctor/asciidoctor/issues/4380
# Currently, there is no access to parent cell from inner document
PARENT_CELL_FIELD_NAME = :@epub3_parent_cell

QUOTE_TAGS = begin
tags = {
monospaced: ['<code>', '</code>', true],
Expand Down Expand Up @@ -796,6 +800,7 @@ def convert_table(node)
else
case cell.style
when :asciidoc
cell.inner_document.instance_variable_set(PARENT_CELL_FIELD_NAME, cell)
cell_content = %(<div class="embed">#{cell.content}</div>)
when :verse
cell_content = %(<div class="verse">#{cell.text}</div>)
Expand Down Expand Up @@ -1156,7 +1161,11 @@ def get_enclosing_chapter(node)
return nil if node.nil?
return node unless get_chapter_filename(node).nil?

node = node.parent
node = if node.instance_variable_defined?(PARENT_CELL_FIELD_NAME)
node.instance_variable_get(PARENT_CELL_FIELD_NAME)
else
node.parent
end
end
end

Expand Down
9 changes: 9 additions & 0 deletions spec/fixtures/image-in-table/book.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
= Image in table
:doctype: book

== Chapter

|===
a|
image::circle.svg[]
|===
3 changes: 3 additions & 0 deletions spec/fixtures/image-in-table/circle.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 7 additions & 0 deletions spec/image_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,13 @@
expect(chapter.content).to include '<img src="square.png" alt="invalid&quot;" width="25em" />'
end

# Test for https://github.com/asciidoctor/asciidoctor-epub3/issues/470
it 'supports image inside table cell' do
book, = to_epub fixture_file('image-in-table/book.adoc')
chapter = book.item_by_href '_chapter.xhtml'
expect(chapter).not_to be_nil
end

# If this test fails for you, make sure you're using gepub >= 1.0.11
it 'adds SVG attribute to EPUB manifest if chapter contains SVG images' do
book, = to_epub fixture_file('svg/book.adoc')
Expand Down

0 comments on commit 9d2cfc2

Please sign in to comment.