Sha256: 73fab933dad2934fac6a23561df1d0c97a95a50eaac742e3785ee65d9ccfbe6e
Contents?: true
Size: 1.45 KB
Versions: 3
Compression:
Stored size: 1.45 KB
Contents
require "addressable/uri" require "kramdown/options" module Kramdown module Options class AlwaysEqual def ==(_other) true end end define(:document_domains, Object, %w{www.gov.uk}, <<~DESCRIPTION) do |val| Defines the domains which are considered local to the document Default: www.gov.uk Used by: KramdownWithAutomaticExternalLinks DESCRIPTION simple_array_validator(val, :document_domains, AlwaysEqual.new) end end module Parser class Govuk < Kramdown::Parser::Kramdown CUSTOM_INLINE_ELEMENTS = %w(govspeak-embed-attachment-link).freeze def initialize(source, options) @document_domains = options[:document_domains] || %w(www.gov.uk) super end def add_link(element, href, title, alt_text = nil, ial = nil) if element.type == :a begin host = Addressable::URI.parse(href).host unless host.nil? || @document_domains.compact.include?(host) element.attr["rel"] = "external" end # rubocop:disable Lint/SuppressedException rescue Addressable::URI::InvalidURIError # it's safe to ignore these very *specific* exceptions end # rubocop:enable Lint/SuppressedException end super end def parse_block_html return false if CUSTOM_INLINE_ELEMENTS.include?(@src[1].downcase) super end end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
govspeak-6.5.4 | lib/kramdown/parser/govuk.rb |
govspeak-6.5.3 | lib/kramdown/parser/govuk.rb |
govspeak-6.5.2 | lib/kramdown/parser/govuk.rb |