diff --git a/lib/asciidoctor-epub3/converter.rb b/lib/asciidoctor-epub3/converter.rb index 8cfcf7e..a78cf27 100644 --- a/lib/asciidoctor-epub3/converter.rb +++ b/lib/asciidoctor-epub3/converter.rb @@ -1000,7 +1000,7 @@ def register_media_file node, target, media_type def resolve_image_attrs node img_attrs = [] - img_attrs << %(alt="#{node.attr 'alt'}") if node.attr? 'alt' + img_attrs << %(alt="#{encode_alt_text node, (node.attr 'alt'), true}") if node.attr? 'alt' # Unlike browsers, Calibre/Kindle *do* scale image if only height is specified # So, in order to match browser behavior, we just always omit height @@ -1765,6 +1765,11 @@ def class_string node def role_valid_class? role role.is_a? String end + + def encode_alt_text node, val, to_attr = false + val = node.sub_specialchars val if (val.include? '<') || (val.include? '&') || (val.include? '>') + to_attr && (val.include? '"') ? (val.gsub '"', '"') : val + end end class DocumentIdGenerator