Sha256: 01f4132a80746f4ab10b001a2cd5acf8e7a66de63b0d693df012a8e952a1649b

Contents?: true

Size: 702 Bytes

Versions: 7

Compression:

Stored size: 702 Bytes

Contents

require "uri"

module Kramdown
  module Parser
    class KramdownWithAutomaticExternalLinks < Kramdown::Parser::Kramdown
      class << self
        attr_writer :document_domains
        def document_domains
          @document_domains || %w(www.gov.uk)
        end
      end

      def add_link(el, href, title, alt_text = nil)
        begin
          host = URI.parse(href).host
          unless host.nil? || (self.class.document_domains.compact.include?(host))
            el.attr['rel'] = 'external'
          end
        rescue URI::InvalidURIError, URI::InvalidComponentError
          # it's safe to ignore these very *specific* exceptions
        end
        super
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
govspeak-1.2.0 lib/kramdown/parser/kramdown_with_automatic_external_links.rb
govspeak-1.1.0 lib/kramdown/parser/kramdown_with_automatic_external_links.rb
govspeak-1.0.1 lib/kramdown/parser/kramdown_with_automatic_external_links.rb
govspeak-1.0.0 lib/kramdown/parser/kramdown_with_automatic_external_links.rb
govspeak-0.8.18 lib/kramdown/parser/kramdown_with_automatic_external_links.rb
govspeak-0.8.17 lib/kramdown/parser/kramdown_with_automatic_external_links.rb
govspeak-0.8.16 lib/kramdown/parser/kramdown_with_automatic_external_links.rb