Sha256: 0d5a1cbbda6548cb44b60858740209b5143041873045df630bba08f3ce05a2e5

Contents?: true

Size: 1.98 KB

Versions: 3

Compression:

Stored size: 1.98 KB

Contents

require_relative 'ja/version'
require_relative 'ja/converter'

require 'asciidoctor/extensions' unless RUBY_ENGINE == 'opal'

include Asciidoctor

Extensions.register do
  treeprocessor do

    process do |document|

      tables = document.find_by context: :table
        tables.each do |table|
        table.rows.head.each do |head|
          head.each do |cell|
            raw_text = get_raw_text(cell)
            cell.text = Asciidoctor::Pdf::Linewrap::Ja::Converter::insert_zero_width_space(raw_text)
          end
        end

        table.rows.body.each do |body|
          body.each do |cell|
            raw_text = get_raw_text(cell)
            cell.text = Asciidoctor::Pdf::Linewrap::Ja::Converter::insert_zero_width_space(raw_text)
          end
        end

        table.rows.foot.each do |foot|
          foot.each do |cell|
            raw_text = get_raw_text(cell)
            cell.text = Asciidoctor::Pdf::Linewrap::Ja::Converter::insert_zero_width_space(raw_text)
          end
        end
      end

      paragraphs = document.find_by context: :paragraph
      paragraphs.each do |paragraph|
        paragraph.lines.each_with_index do |line, i|
          paragraph.lines[i] = Asciidoctor::Pdf::Linewrap::Ja::Converter::insert_zero_width_space(line)
        end
      end

      list_items = document.find_by context: :list_item
      list_items.each do |list_item|
        raw_text = get_raw_text(list_item)
        list_item.text = Asciidoctor::Pdf::Linewrap::Ja::Converter::insert_zero_width_space(raw_text)
      end

      admonitions = document.find_by context: :admonition
      admonitions.each do |admonition|
        admonition.lines.each_with_index do |line, i|
          admonition.lines[i] = Asciidoctor::Pdf::Linewrap::Ja::Converter::insert_zero_width_space(line)
        end
      end
    end

    def get_raw_text(item)
      if item.instance_variable_defined?('@text')
        return item.instance_variable_get('@text')
      else
        return item.text
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
asciidoctor-pdf-linewrap-ja-0.8.0 lib/asciidoctor/pdf/linewrap/ja.rb
asciidoctor-pdf-linewrap-ja-0.7.1 lib/asciidoctor/pdf/linewrap/ja.rb
asciidoctor-pdf-linewrap-ja-0.7.0 lib/asciidoctor/pdf/linewrap/ja.rb