Sha256: 4141913a2d30107f893170b30c769f38caadeff1dcb7742c3c6017ef8dca4342

Contents?: true

Size: 1.13 KB

Versions: 8

Compression:

Stored size: 1.13 KB

Contents

# frozen_string_literal: true

module Stepmod
  module Utils
    module Converters
      class Strong < ReverseAdoc::Converters::Base
        BLANK_CHARS = "{blank}".freeze

        def convert(node, state = {})
          content = treat_children(node, state.merge(already_strong: true))
          if content.strip.empty? || state[:already_strong]
            content
          else
            handle_express_escape_seq(node, "#{content[/^\s*/]}*#{content.strip}*#{content[/\s*$/]}")
          end
        end

        private

        def handle_express_escape_seq(node, content)
          res = content
          if braces_sibling?(node.previous, true)
            res = "#{BLANK_CHARS}#{res}"
          end
          if braces_sibling?(node.next)
            res = "#{res}#{BLANK_CHARS}"
          end
          res
        end

        def braces_sibling?(sibling, end_of_text = false)
          match = end_of_text ? /\($/ : /^\)/
          sibling && sibling.text? && sibling.text =~ match
        end
      end

      ReverseAdoc::Converters.register :strong, Strong.new
      ReverseAdoc::Converters.register :b,      Strong.new
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
stepmod-utils-0.3.5 lib/stepmod/utils/converters/strong.rb
stepmod-utils-0.3.4 lib/stepmod/utils/converters/strong.rb
stepmod-utils-0.3.2 lib/stepmod/utils/converters/strong.rb
stepmod-utils-0.3.1 lib/stepmod/utils/converters/strong.rb
stepmod-utils-0.3.0 lib/stepmod/utils/converters/strong.rb
stepmod-utils-0.2.7 lib/stepmod/utils/converters/strong.rb
stepmod-utils-0.2.6 lib/stepmod/utils/converters/strong.rb
stepmod-utils-0.2.5 lib/stepmod/utils/converters/strong.rb