lib/asciidoctor_fb2.rb in asciidoctor-fb2-0.2.3 vs lib/asciidoctor_fb2.rb in asciidoctor-fb2-0.2.4

- old
+ new

@@ -4,10 +4,12 @@ require 'asciidoctor/converter' require 'fb2rb' module Asciidoctor module FB2 + DATA_DIR = File.expand_path(File.join(__dir__, '..', 'data')) + # Converts AsciiDoc documents to FB2 e-book formats class Converter < Asciidoctor::Converter::Base # rubocop:disable Metrics/ClassLength include ::Asciidoctor::Writer CSV_DELIMITER_REGEX = /\s*,\s*/.freeze @@ -23,10 +25,12 @@ end # @param node [Asciidoctor::Document] def convert_document(node) # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/MethodLength, Metrics/PerceivedComplexity @book = FB2rb::Book.new + @book.add_stylesheet('text/css', File.join(DATA_DIR, 'fb2.css')) + document_info = @book.description.document_info title_info = @book.description.title_info title_info.book_title = node.doctitle title_info.lang = node.attr('lang', 'en') @@ -262,20 +266,24 @@ doc end # @param node [Asciidoctor::AbstractNode] # @param target [String] - def register_binary(node, target) # rubocop:disable Metrics/MethodLength + def register_binary(node, target) # rubocop:disable Metrics/AbcSize, Metrics/MethodLength unless Asciidoctor::Helpers.uriish?(target) out_dir = node.attr('outdir', nil, true) || doc_option(node.document, :to_dir) fs_path = File.join(out_dir, target) unless File.readable?(fs_path) base_dir = root_document(node.document).base_dir 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!('\\', '_') + @book.add_binary(target, fs_path) target = %(##{target}) end end @@ -359,10 +367,12 @@ lines * "\n" end # @param node [Asciidoctor::Table] def convert_table(node) # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/MethodLength, Metrics/PerceivedComplexity - lines = ['<table>'] + lines = [] + lines << %(<subtitle>#{node.captioned_title}</subtitle>) if node.title? + lines << '<table>' node.rows.to_h.each do |tsec, rows| # rubocop:disable Metrics/BlockLength next if rows.empty? rows.each do |row| lines << '<tr>'