Sha256: 05ad75d1e8add6c9ea8327119c162048e0972b4961ad9b4110608a73fc1a3cca

Contents?: true

Size: 1.24 KB

Versions: 10

Compression:

Stored size: 1.24 KB

Contents

module ReverseAsciidoctor
  module Converters
    class Ol < Base
      def convert(node, state = {})
        id = node['id']
        anchor = id ? "[[#{id}]]\n" : ""
        ol_count = state.fetch(:ol_count, 0) + 1
        attrs = ol_attrs(node)
        "\n#{anchor}#{attrs}" << treat_children(node, state.merge(ol_count: ol_count))
      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"
                else
                  nil
                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

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

Version data entries

10 entries across 10 versions & 2 rubygems

Version Path
reverse_adoc-0.2.8 lib/reverse_asciidoctor/converters/ol.rb
reverse_adoc-0.2.7 lib/reverse_asciidoctor/converters/ol.rb
reverse_adoc-0.2.6 lib/reverse_asciidoctor/converters/ol.rb
reverse_adoc-0.2.5 lib/reverse_asciidoctor/converters/ol.rb
reverse_adoc-0.2.4 lib/reverse_asciidoctor/converters/ol.rb
reverse_adoc-0.2.3 lib/reverse_asciidoctor/converters/ol.rb
reverse_asciidoctor-0.2.2 lib/reverse_asciidoctor/converters/ol.rb
reverse_asciidoctor-0.2.1 lib/reverse_asciidoctor/converters/ol.rb
reverse_asciidoctor-0.2.0 lib/reverse_asciidoctor/converters/ol.rb
reverse_asciidoctor-0.1.0 lib/reverse_asciidoctor/converters/ol.rb