Sha256: 822615587a803833f60ecba661de13e6bb85fe972a9ba3987cc0633633a18fad

Contents?: true

Size: 763 Bytes

Versions: 13

Compression:

Stored size: 763 Bytes

Contents

require "reverse_adoc"

module Stepmod
  module Utils
    module Converters
      class Base < ReverseAdoc::Converters::Base
        PREFIXES_REGEX = /([Ff]ormula|[Ff]igure|[Tt]able)\s*/.freeze

        def treat_children(node, state)
          updated_node = remove_prefixes(node)

          updated_node.children.inject("") do |memo, child|
            memo << treat(child, state)
          end
        end

        private

        def remove_prefixes(node)
          node.children.each_with_index do |child, index|
            if child.text.match(PREFIXES_REGEX) && node.children[index + 1]&.name == "a"
              child.content = child.content.gsub(PREFIXES_REGEX, "")
            end
          end

          node
        end
      end
    end
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
stepmod-utils-0.6.6 lib/stepmod/utils/converters/base.rb
stepmod-utils-0.6.5 lib/stepmod/utils/converters/base.rb
stepmod-utils-0.6.3 lib/stepmod/utils/converters/base.rb
stepmod-utils-0.6.2 lib/stepmod/utils/converters/base.rb
stepmod-utils-0.6.1 lib/stepmod/utils/converters/base.rb
stepmod-utils-0.6.0 lib/stepmod/utils/converters/base.rb
stepmod-utils-0.5.0 lib/stepmod/utils/converters/base.rb
stepmod-utils-0.4.14 lib/stepmod/utils/converters/base.rb
stepmod-utils-0.4.13 lib/stepmod/utils/converters/base.rb
stepmod-utils-0.4.12 lib/stepmod/utils/converters/base.rb
stepmod-utils-0.4.11 lib/stepmod/utils/converters/base.rb
stepmod-utils-0.4.10 lib/stepmod/utils/converters/base.rb
stepmod-utils-0.4.9 lib/stepmod/utils/converters/base.rb