Class: Kramdown::Parser::Govuk

Inherits:
Kramdown
  • Object
show all
Defined in:
lib/kramdown/parser/govuk.rb

Constant Summary collapse

CUSTOM_INLINE_ELEMENTS =
%w(govspeak-embed-attachment-link).freeze

Instance Method Summary collapse

Constructor Details

#initialize(source, options) ⇒ Govuk

Returns a new instance of Govuk.



26
27
28
29
# File 'lib/kramdown/parser/govuk.rb', line 26

def initialize(source, options)
  @document_domains = options[:document_domains] || %w(www.gov.uk)
  super
end

Instance Method Details



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/kramdown/parser/govuk.rb', line 31

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

#parse_block_htmlObject



47
48
49
50
51
# File 'lib/kramdown/parser/govuk.rb', line 47

def parse_block_html
  return false if CUSTOM_INLINE_ELEMENTS.include?(@src[1].downcase)

  super
end