Sha256: 6447175849105bbda9f3eea3c635a5fc0d7b7c3b353f0e9df9ed9862ff6253a3

Contents?: true

Size: 806 Bytes

Versions: 3

Compression:

Stored size: 806 Bytes

Contents

module Storyblok::Richtext
  module Marks
    class Link < Mark

      def matching
        @node['type'] === 'link'
      end

      def tag
        attrs = @node['attrs']

        if attrs['anchor'].is_a?(String) and !attrs['anchor'].empty?
          attrs['href'] = "#{attrs['href']}##{attrs['anchor']}"
          attrs.delete('anchor')
        end

        if attrs['linktype'].is_a?(String) and attrs['linktype'] == 'email'
          emailContainer = attrs['href']
          attrs['href'] = "mailto:#{emailContainer}"
        end

        if attrs['custom'].is_a?(Hash)
          for item in attrs['custom'] do
            attrs[item[0]] = item[1]
          end
          attrs.delete('custom')
        end

        [{
          tag: "a",
          attrs: attrs
        }]
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
storyblok-richtext-renderer-0.0.10 lib/storyblok/richtext/html_renderer/marks/link.rb
storyblok-richtext-renderer-0.0.9 lib/storyblok/richtext/html_renderer/marks/link.rb
storyblok-richtext-renderer-0.0.8 lib/storyblok/richtext/html_renderer/marks/link.rb