lib/asciidoctor/i18n/processor.rb in asciidoctor-i18n-0.1.2 vs lib/asciidoctor/i18n/processor.rb in asciidoctor-i18n-0.1.3

- old
+ new

@@ -27,11 +27,11 @@ return unless src.title src.title = translator.translate(src.title) end def process_block(src, translator) - src.lines = translator.translate(concatenated_lines(src)) + src.lines = translator.translate(concatenated_lines(src, src.lines)) end def process_table(src, translator) (src.rows.head + src.rows.body).each do |row| row.each do |cell| @@ -39,12 +39,13 @@ end end end def process_list_item(src, translator) - text = src.instance_variable_get(:@text) - return unless text + raw = src.instance_variable_get(:@text) + return unless raw + text = concatenated_lines(src, raw.split("\n")).join("\n") src.text = translator.translate(text) end def process_table_cell(src, translator) if src.style != :asciidoc @@ -55,29 +56,29 @@ process_document(src.inner_document, translator) end end # concat continuous lines if no hard line break exists - def concatenated_lines(src) - return src.lines if skip_concatenate?(src) - result = [src.lines.first] - src.lines.drop(1).each do |line| + def concatenated_lines(src, lines) + return lines if skip_concatenate?(src, lines) + result = [lines.first] + lines.drop(1).each do |line| if line_break?(src, result.last, line) result.push(line) else result[-1] = result[-1] + " #{line}" end end result end - def skip_concatenate?(src) - src.lines.empty? || src.content_model != :simple + def skip_concatenate?(src, lines) + lines.empty? || !%i[simple compound].include?(src.content_model) end def line_break?(src, prev_line, next_line) - content = src.apply_subs([prev_line, next_line].join("\n"), src.subs) - content.include?('<br>') && !content.strip.end_with?('<br>') + content = src.apply_subs("#{prev_line}\n#{next_line}", src.subs) + content.gsub(/<br>\s*$/).include?('<br>') end end end end