diff options
| -rw-r--r-- | CHANGELOG.adoc | 1 | ||||
| -rw-r--r-- | lib/asciidoctor-epub3/converter.rb | 13 | ||||
| -rw-r--r-- | spec/fixtures/image-dimensions/chapter.adoc | 2 | ||||
| -rw-r--r-- | spec/image_spec.rb | 2 |
4 files changed, 15 insertions, 3 deletions
diff --git a/CHANGELOG.adoc b/CHANGELOG.adoc index 3313b21..948fffc 100644 --- a/CHANGELOG.adoc +++ b/CHANGELOG.adoc @@ -10,6 +10,7 @@ For a detailed view of what has changed, refer to the {uri-repo}/commits/master[ * add XML declarations to XHTML files (#424 by @abbrev) * bump the oldest supported Ruby to 2.6 * bump the oldest supported Asciidoctor to 2.0 +* escape double quotes in alt text == 1.5.1 (2021-04-29) - @slonopotamus diff --git a/lib/asciidoctor-epub3/converter.rb b/lib/asciidoctor-epub3/converter.rb index e5a228e..93b3bae 100644 --- a/lib/asciidoctor-epub3/converter.rb +++ b/lib/asciidoctor-epub3/converter.rb @@ -1057,9 +1057,14 @@ document.addEventListener('DOMContentLoaded', function(event, reader) { @media_files[target] ||= { path: fs_path, media_type: media_type } end + # @param node [Asciidoctor::Block] + # @return [Array<String>] def resolve_image_attrs(node) img_attrs = [] - img_attrs << %(alt="#{node.attr 'alt'}") if node.attr? 'alt' + + unless (alt = encode_attribute_value(node.alt)).empty? + img_attrs << %(alt="#{alt}") + end # Unlike browsers, Calibre/Kindle *do* scale image if only height is specified # So, in order to match browser behavior, we just always omit height @@ -1145,6 +1150,8 @@ document.addEventListener('DOMContentLoaded', function(event, reader) { </figure>) end + # @param node [Asciidoctor::Block] + # @return [String] def convert_image(node) target = node.image_uri node.attr 'target' register_media_file node, target, 'image' @@ -1333,6 +1340,10 @@ document.addEventListener('DOMContentLoaded', function(event, reader) { node.content_model == :simple ? %(<p>#{node.content}</p>) : node.content end + def encode_attribute_value(val) + val.gsub '"', '"' + end + # FIXME: merge into with xml_sanitize helper def xml_sanitize(value, target = :attribute) sanitized = value.include?('<') ? value.gsub(XML_ELEMENT_RX, '').strip.tr_s(' ', ' ') : value diff --git a/spec/fixtures/image-dimensions/chapter.adoc b/spec/fixtures/image-dimensions/chapter.adoc index 4080080..b645a4f 100644 --- a/spec/fixtures/image-dimensions/chapter.adoc +++ b/spec/fixtures/image-dimensions/chapter.adoc @@ -4,4 +4,4 @@ image::square.png[100x100,100,100] image::square.png[50x50,50,50] image::square.png[50x?,50] image::square.png[25%x?,25%] -image::square.png[invalid,25em] +image::square.png[invalid",25em] diff --git a/spec/image_spec.rb b/spec/image_spec.rb index f9bd2ea..e178af8 100644 --- a/spec/image_spec.rb +++ b/spec/image_spec.rb @@ -78,7 +78,7 @@ describe 'Asciidoctor::Epub3::Converter - Image' do expect(chapter.content).to include '<img src="square.png" alt="50x50" width="50" />' expect(chapter.content).to include '<img src="square.png" alt="50x?" width="50" />' expect(chapter.content).to include '<img src="square.png" alt="25%x?" style="width: 25%" />' - expect(chapter.content).to include '<img src="square.png" alt="invalid" width="25em" />' + expect(chapter.content).to include '<img src="square.png" alt="invalid"" width="25em" />' end # If this test fails for you, make sure you're using gepub >= 1.0.11 |
