Sha256: d196399a984884586ef13918ff66fdac0319d678a426e4bfa7f65795d28e63e8

Contents?: true

Size: 1.15 KB

Versions: 10

Compression:

Stored size: 1.15 KB

Contents

# frozen_string_literal: true

require "uri"

module Stepmod
  module Utils
    module Converters
      class A < ReverseAdoc::Converters::Base
        def convert(node, state = {})
          name  = treat_children(node, state)
          href  = node['href']
          title = extract_title(node)
          id = node['id'] || node['name']

          id = id&.gsub(/\s/, "")&.gsub(/__+/, "_")

          if /^_Toc\d+$|^_GoBack$/.match id
            ""
          elsif !id.nil? && !id.empty?
            "[[#{id}]]"
          elsif href.to_s.start_with?('#')
            href = href.sub(/^#/, "").gsub(/\s/, "").gsub(/__+/, "_")
            if name.empty?
              "<<#{href}>>"
            else
              "<<#{href},#{name}>>"
            end
          elsif href.to_s.empty?
            name
          else
            name = title if name.empty?
            href = "link:#{href}" unless href.to_s =~ URI::DEFAULT_PARSER.make_regexp
            link = "#{href}[#{name}]"
            # link.prepend(' ')
            link = " #{link}"
            link
          end
        end

        private

      end

      ReverseAdoc::Converters.register :a, A.new
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

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