lib/asciidoctor_fb2.rb in asciidoctor-fb2-0.6.0 vs lib/asciidoctor_fb2.rb in asciidoctor-fb2-0.7.0
- old
+ new
@@ -280,11 +280,11 @@
end
# @param node [Asciidoctor::Inline]
def convert_inline_image(node)
image_attrs = register_binary(node, node.image_uri(node.target), 'image')
- %(<image #{image_attrs * ' '}/>)
+ %(<image #{image_attrs.sort! * ' '}/>)
end
# @param node [Asciidoctor::Inline]
def convert_inline_indexterm(node)
node.type == :visible ? node.text : ''
@@ -299,15 +299,22 @@
def convert_colist(node)
convert_olist(node)
end
# @param node [Asciidoctor::Block]
- def convert_image(node)
+ def convert_image(node) # rubocop:disable Metrics/AbcSize
image_attrs = register_binary(node, node.image_uri(node.attr('target')), 'image')
image_attrs << %(title="#{node.captioned_title}") if node.title?
image_attrs << %(id="#{node.id}") if node.id
- %(<p><image #{image_attrs * ' '}/></p>)
+
+ p_style = []
+ p_style << %(float: #{node.attr 'float'}) if node.attr? 'float'
+ p_style << %(text-align: #{node.attr 'align'}) if node.attr? 'align'
+
+ p_attrs = []
+ p_attrs << %(style="#{p_style.sort! * '; '}") unless p_style.empty?
+ %(<p #{p_attrs.sort! * ' '}><image #{image_attrs.sort! * ' '}/></p>)
end
# @param node [Asciidoctor::Block]
def convert_open(node)
convert_paragraph(node)
@@ -337,12 +344,12 @@
fs_path = File.join(base_dir, target)
end
if File.readable?(fs_path)
# Calibre fails to load images if they contain path separators
- target.sub!('/', '_')
- target.sub!('\\', '_')
+ target.gsub!('/', '_')
+ target.gsub!('\\', '_')
mime_type = determine_mime_type(target, media_type)
@book.add_binary(target, fs_path, mime_type)
target = %(##{target})
end
@@ -350,15 +357,30 @@
image_attrs = [%(l:href="#{target}")]
image_attrs << %(alt="#{node.attr('alt')}") if node.attr? 'alt'
end
+ ADMONITION_ICONS = {
+ 'caution' => '🔥',
+ 'important' => '❗',
+ 'note' => 'ℹ️',
+ 'tip' => '💡',
+ 'warning' => '⚠️'
+ }.freeze
+
# @param node [Asciidoctor::Block]
def convert_admonition(node)
- lines = [%(<p><strong>#{node.title || node.caption}:</strong>
-#{node.content}
-</p>)]
+ lines = ['<p>']
+
+ lines << if node.document.attr?('icons', 'font') && (icon = ADMONITION_ICONS[node.attr 'name'])
+ %(#{icon} )
+ else
+ %(<strong>#{node.title || node.caption}:</strong>)
+ end
+
+ lines << node.content
+ lines << '</p>'
lines << '<empty-line/>' unless node.has_role?('last')
lines * "\n"
end
# @param node [Asciidoctor::Block]
@@ -463,10 +485,10 @@
%(halign="#{cell.attr 'halign'}"),
%(valign="#{cell.attr 'valign'}")
]
cell_attrs << %(colspan="#{cell.colspan}") if cell.colspan
cell_attrs << %(rowspan="#{cell.rowspan}") if cell.rowspan
- lines << %(<#{cell_tag_name} #{cell_attrs * ' '}>#{cell_content}</#{cell_tag_name}>)
+ lines << %(<#{cell_tag_name} #{cell_attrs.sort! * ' '}>#{cell_content}</#{cell_tag_name}>)
end
lines << '</tr>'
end
end
lines << '</table>'