Sha256: e23565b11a34ded5e233126f5f5bb9bed0562ded4d37d6e8e201adbe44b96e85

Contents?: true

Size: 1.71 KB

Versions: 36

Compression:

Stored size: 1.71 KB

Contents

# frozen_string_literal: true

module Stepmod
  module Utils
    module Converters
      class Ol < ReverseAdoc::Converters::Base
        def convert(node, state = {})
          id = node["id"]
          anchor = id ? "[[#{id}]]\n" : ""
          ol_count = state.fetch(:ol_count, 0) + 1
          attrs = ol_attrs(node)
          children_s = treat_children(node, state.merge(
                                              ol_count: ol_count,
                                              tdsinglepara: true,
                                            ))

          "\n\n#{anchor}#{attrs}#{children_s}\n"
          # Why do we add this?
          # res = "\n" + res if node.parent && node.parent.name == 'note'
        end

        def number_style(node)
          style = case node["style"]
                  when "1" then "arabic"
                  when "A" then "upperalpha"
                  when "a" then "loweralpha"
                  when "I" then "upperroman"
                  when "i" then "lowerroman"
                  end
        end

        def ol_attrs(node)
          style = number_style(node)
          reversed = "%reversed" if node["reversed"]
          start = "start=#{node['start']}" if node["start"]
          type = "type=#{node['type']}" if node["type"]
          attrs = []
          attrs << style if style
          attrs << reversed if reversed
          attrs << start if start
          attrs << type if type
          if attrs.empty?
            ""
          else
            "[#{attrs.join(',')}]\n"
          end
        end
      end

      ReverseAdoc::Converters.register :ol, Ol.new
      ReverseAdoc::Converters.register :ul, Ol.new
      ReverseAdoc::Converters.register :dir, Ol.new
    end
  end
end

Version data entries

36 entries across 36 versions & 1 rubygems

Version Path
stepmod-utils-0.4.8 lib/stepmod/utils/converters/ol.rb
stepmod-utils-0.4.7 lib/stepmod/utils/converters/ol.rb
stepmod-utils-0.4.6 lib/stepmod/utils/converters/ol.rb
stepmod-utils-0.4.5 lib/stepmod/utils/converters/ol.rb
stepmod-utils-0.4.2 lib/stepmod/utils/converters/ol.rb
stepmod-utils-0.4.1 lib/stepmod/utils/converters/ol.rb
stepmod-utils-0.4.0 lib/stepmod/utils/converters/ol.rb
stepmod-utils-0.3.37 lib/stepmod/utils/converters/ol.rb
stepmod-utils-0.3.36 lib/stepmod/utils/converters/ol.rb
stepmod-utils-0.3.35 lib/stepmod/utils/converters/ol.rb
stepmod-utils-0.3.34 lib/stepmod/utils/converters/ol.rb
stepmod-utils-0.3.33 lib/stepmod/utils/converters/ol.rb
stepmod-utils-0.3.32 lib/stepmod/utils/converters/ol.rb
stepmod-utils-0.3.31 lib/stepmod/utils/converters/ol.rb
stepmod-utils-0.3.30 lib/stepmod/utils/converters/ol.rb
stepmod-utils-0.3.29 lib/stepmod/utils/converters/ol.rb
stepmod-utils-0.3.28 lib/stepmod/utils/converters/ol.rb
stepmod-utils-0.3.27 lib/stepmod/utils/converters/ol.rb
stepmod-utils-0.3.26 lib/stepmod/utils/converters/ol.rb
stepmod-utils-0.3.25 lib/stepmod/utils/converters/ol.rb