Class: Kramdown::Parser::Govuk
- Inherits:
-
Kramdown
- Object
- Kramdown
- Kramdown::Parser::Govuk
- Defined in:
- lib/kramdown/parser/govuk.rb
Constant Summary collapse
- CUSTOM_INLINE_ELEMENTS =
%w[govspeak-embed-attachment-link].freeze
Instance Method Summary collapse
- #add_link(element, href, title, alt_text = nil, ial = nil) ⇒ Object
-
#initialize(source, options) ⇒ Govuk
constructor
A new instance of Govuk.
- #parse_block_html ⇒ Object
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, ) @document_domains = [:document_domains] || %w[www.gov.uk] super end |
Instance Method Details
#add_link(element, href, title, alt_text = nil, ial = nil) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# 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 rescue Addressable::URI::InvalidURIError # it's safe to ignore these very *specific* exceptions end end super end |
#parse_block_html ⇒ Object
46 47 48 49 50 |
# File 'lib/kramdown/parser/govuk.rb', line 46 def parse_block_html return false if CUSTOM_INLINE_ELEMENTS.include?(@src[1].downcase) super end |