diff options
| author | Dan Allen <dan.j.allen@gmail.com> | 2021-11-09 23:36:09 -0700 |
|---|---|---|
| committer | Dan Allen <dan.j.allen@gmail.com> | 2021-11-10 00:36:21 -0700 |
| commit | 2f2ecfa93d8540f952b29196f59db35002cf1df7 (patch) | |
| tree | 8c801d476590d845cd43944c836cfce61c5dad78 | |
| parent | 9cbd34701d066f845eb9fc53c2f5a552d92e11cd (diff) | |
simplify logic branches for converting different image types and modes
| -rw-r--r-- | lib/asciidoctor/converter/html5.rb | 24 |
1 files changed, 14 insertions, 10 deletions
diff --git a/lib/asciidoctor/converter/html5.rb b/lib/asciidoctor/converter/html5.rb index 1684310c..336dd4b9 100644 --- a/lib/asciidoctor/converter/html5.rb +++ b/lib/asciidoctor/converter/html5.rb @@ -627,16 +627,18 @@ Your browser does not support the audio tag. target = node.attr 'target' width_attr = (node.attr? 'width') ? %( width="#{node.attr 'width'}") : '' height_attr = (node.attr? 'height') ? %( height="#{node.attr 'height'}") : '' - if ((node.attr? 'format', 'svg') || (target.include? '.svg')) && node.document.safe < SafeMode::SECURE && - ((svg = node.option? 'inline') || (obj = node.option? 'interactive')) - if svg + if ((node.attr? 'format', 'svg') || (target.include? '.svg')) && node.document.safe < SafeMode::SECURE + if node.option? 'inline' img = (read_svg_contents node, target) || %(<span class="alt">#{node.alt}</span>) - elsif obj + elsif node.option? 'interactive' fallback = (node.attr? 'fallback') ? %(<img src="#{node.image_uri node.attr 'fallback'}" alt="#{encode_attribute_value node.alt}"#{width_attr}#{height_attr}#{@void_element_slash}>) : %(<span class="alt">#{node.alt}</span>) img = %(<object type="image/svg+xml" data="#{node.image_uri target}"#{width_attr}#{height_attr}>#{fallback}</object>) + else + img = %(<img src="#{node.image_uri target}" alt="#{encode_attribute_value node.alt}"#{width_attr}#{height_attr}#{@void_element_slash}>) end + else + img = %(<img src="#{node.image_uri target}" alt="#{encode_attribute_value node.alt}"#{width_attr}#{height_attr}#{@void_element_slash}>) end - img ||= %(<img src="#{node.image_uri target}" alt="#{encode_attribute_value node.alt}"#{width_attr}#{height_attr}#{@void_element_slash}>) img = %(<a class="image" href="#{node.attr 'link'}"#{(append_link_constraint_attrs node).join}>#{img}</a>) if node.attr? 'link' id_attr = node.id ? %( id="#{node.id}") : '' classes = ['imageblock'] @@ -1199,16 +1201,18 @@ Your browser does not support the video tag. attrs << %( height="#{node.attr 'height'}") if node.attr? 'height' attrs << %( title="#{node.attr 'title'}") if node.attr? 'title' attrs = attrs.empty? ? '' : attrs.join - if type != 'icon' && ((node.attr? 'format', 'svg') || (target.include? '.svg')) && - node.document.safe < SafeMode::SECURE && ((svg = node.option? 'inline') || (obj = node.option? 'interactive')) - if svg + if type != 'icon' && ((node.attr? 'format', 'svg') || (target.include? '.svg')) && node.document.safe < SafeMode::SECURE + if node.option? 'inline' img = (read_svg_contents node, target) || %(<span class="alt">#{node.alt}</span>) - elsif obj + elsif node.option? 'interactive' fallback = (node.attr? 'fallback') ? %(<img src="#{node.image_uri node.attr 'fallback'}" alt="#{encode_attribute_value node.alt}"#{attrs}#{@void_element_slash}>) : %(<span class="alt">#{node.alt}</span>) img = %(<object type="image/svg+xml" data="#{node.image_uri target}"#{attrs}>#{fallback}</object>) + else + img = %(<img src="#{type == 'icon' ? (node.icon_uri target) : (node.image_uri target)}" alt="#{encode_attribute_value node.alt}"#{attrs}#{@void_element_slash}>) end + else + img = %(<img src="#{type == 'icon' ? (node.icon_uri target) : (node.image_uri target)}" alt="#{encode_attribute_value node.alt}"#{attrs}#{@void_element_slash}>) end - img ||= %(<img src="#{type == 'icon' ? (node.icon_uri target) : (node.image_uri target)}" alt="#{encode_attribute_value node.alt}"#{attrs}#{@void_element_slash}>) end img = %(<a class="image" href="#{node.attr 'link'}"#{(append_link_constraint_attrs node).join}>#{img}</a>) if node.attr? 'link' if (role = node.role) |
