Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable image-based callouts #486

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 33 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}").to_s, '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,16 @@ 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>)
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}")
%(<img src="#{src}" class="inline conum"/>)
end
end

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