Sha256: 5f4b0d93fe3c3333ce1028a5c51b3d087182b3762442ae98271615bc2179d6e1

Contents?: true

Size: 574 Bytes

Versions: 2

Compression:

Stored size: 574 Bytes

Contents

# frozen_string_literal: true

module Caramelize
  class CamelCaseToWikiLinks
    def initialize(body)
      @body = body
    end

    # take an input stream and convert all wikka syntax to markdown syntax
    def run
      migrated_body = @body.dup

      migrated_body.gsub!(/([^\[\|\w\S])([A-Z]\w+[A-Z]\w+)([^\]])/) { "#{::Regexp.last_match(1)}#{format_link(::Regexp.last_match(2))}#{::Regexp.last_match(3)}" }

      migrated_body
    end

    private

    def format_link(link)
      link.gsub!(' ', '_')
      link.gsub!('.', '')
      "[[#{link}]]"
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
caramelize-1.2.1 lib/caramelize/filters/camel_case_to_wiki_links.rb
caramelize-1.2.0 lib/caramelize/filters/camel_case_to_wiki_links.rb