Skip to content

Commit

Permalink
Enable image-based callouts
Browse files Browse the repository at this point in the history
  • Loading branch information
someth2say committed Nov 19, 2024
1 parent 72c5d6f commit 0694381
Showing 1 changed file with 34 additions and 12 deletions.
46 changes: 34 additions & 12 deletions lib/asciidoctor-epub3/converter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -838,15 +838,30 @@ def convert_table(node)
end

def convert_colist(node)
lines = ['<div class="callout-list">
<ol>']
num = CALLOUT_START_NUM
node.items.each_with_index do |item, i|
lines << %(<li><i class="conum" data-value="#{i + 1}">#{num}</i> #{item.text}#{item.content if item.blocks?}</li>)
num = num.next
lines = ['<div class="callout-list">']
font_icons = (node.document.attr? 'icons', 'font')
if font_icons
num = CALLOUT_START_NUM
lines << '<ol>'
node.items.each_with_index do |item, i|
lines << %(<li><i class="conum" data-value="#{i + 1}">#{num}</i> #{item.text}#{item.content if item.blocks?}</li>)
num = num.next
end
lines << '</ol>'
else
num = 1
lines << '<table class="callout-list">'
node.items.each_with_index do |item, i|
lines << '<tr>'
lines << %(<td class="conum"><img class="conum" src="#{node.icon_uri "callouts/#{num}"}" alt="#{num}"/></td>)
lines << %(<td>#{item.text}#{item.blocks? ? LF + item.content : ''}</td>)
lines << '</tr>'
register_media_file node, "#{node.icon_uri "callouts/#{i + 1}"}", 'image'
num = num.next
end
lines << '</table>'
end
lines << '</ol>
</div>'
lines << '</div>'
end

# TODO: add complex class if list has nested blocks
Expand Down Expand Up @@ -1243,10 +1258,17 @@ def convert_inline_button(node)
end

def convert_inline_callout(node)
num = CALLOUT_START_NUM
int_num = node.text.to_i
(int_num - 1).times { num = num.next }
%(<i class="conum" data-value="#{int_num}">#{num}</i>)
lines = ''
font_icons = (node.document.attr? 'icons', 'font')
if font_icons
num = CALLOUT_START_NUM
int_num = node.text.to_i
(int_num - 1).times { num = num.next }
%(<i class="conum" data-value="#{int_num}">#{num}</i>)
else
src = node.icon_uri("callouts/#{node.text}")
lines << %(<img src="#{src}" class="inline conum"/>)
end
end

# @param node [Asciidoctor::Inline]
Expand Down

0 comments on commit 0694381

Please sign in to comment.