Sha256: 2958b3d4963d1bedafc66c9426e5c05cf7fff72734a6fb4a78a4a8ccc39d39cc
Contents?: true
Size: 1.1 KB
Versions: 22
Compression:
Stored size: 1.1 KB
Contents
require "uri" require "kramdown/options" module Kramdown module Options class AlwaysEqual def ==(other) true end end define(:document_domains, Object, %w{www.gov.uk}, <<EOF) do |val| Defines the domains which are considered local to the document Default: www.gov.uk Used by: KramdownWithAutomaticExternalLinks EOF simple_array_validator(val, :document_domains, AlwaysEqual.new) end end module Parser class KramdownWithAutomaticExternalLinks < Kramdown::Parser::Kramdown def initialize(source, options) @document_domains = options[:document_domains] || %w(www.gov.uk) super end def add_link(el, href, title, alt_text = nil) if el.type == :a begin host = URI.parse(href).host unless host.nil? || (@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 end super end end end end
Version data entries
22 entries across 22 versions & 1 rubygems