Sha256: fb713329d83b4e55f3eeafda8d6e04a9937ab01fbfb0fd56fbbfb648ecf385b9

Contents?: true

Size: 1.26 KB

Versions: 8

Compression:

Stored size: 1.26 KB

Contents

# frozen_string_literal: true

module Stepmod
  module Utils
    module Converters
      class Em < ReverseAdoc::Converters::Base
        def convert(node, state = {})
          italic_converted(node, state)
        end

        private

        def italic_converted(node, state)
          cloned_node = node.clone
          equations = extract_equations(cloned_node)
          content = treat_children(cloned_node, state.merge(already_italic: true))
          equation_content = equations.map do |equation|
            treat(equation, state.merge(equation: true, already_italic: true))
          end

          content = if content.strip.empty? || state[:already_italic] || state[:equation]
            content
          else
            "#{content[/^\s*/]}_#{content.strip}_#{content[/\s*$/]}"
          end

          [content, equation_content].compact.join("")
        end

        def extract_equations(node)
          equations = []

          node.children.each do |n|
            next if n.name != "eqn"

            equations << n
            n.unlink
          end

          equations
        end
      end

      ReverseAdoc::Converters.register :em, Em.new
      ReverseAdoc::Converters.register :i,  Em.new
      ReverseAdoc::Converters.register :cite, Em.new
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
stepmod-utils-0.4.8 lib/stepmod/utils/converters/em_express_description.rb
stepmod-utils-0.4.7 lib/stepmod/utils/converters/em_express_description.rb
stepmod-utils-0.4.6 lib/stepmod/utils/converters/em_express_description.rb
stepmod-utils-0.4.5 lib/stepmod/utils/converters/em_express_description.rb
stepmod-utils-0.4.2 lib/stepmod/utils/converters/em_express_description.rb
stepmod-utils-0.4.1 lib/stepmod/utils/converters/em_express_description.rb
stepmod-utils-0.4.0 lib/stepmod/utils/converters/em_express_description.rb
stepmod-utils-0.3.37 lib/stepmod/utils/converters/em_express_description.rb