Class: Kramdown::Parser::KramdownWithAutomaticExternalLinks
- Inherits:
-
Kramdown
- Object
- Kramdown
- Kramdown::Parser::KramdownWithAutomaticExternalLinks
- Defined in:
- lib/kramdown/parser/kramdown_with_automatic_external_links.rb
Instance Method Summary collapse
- #add_link(element, href, title, alt_text = nil, ial = nil) ⇒ Object
-
#initialize(source, options) ⇒ KramdownWithAutomaticExternalLinks
constructor
A new instance of KramdownWithAutomaticExternalLinks.
Constructor Details
#initialize(source, options) ⇒ KramdownWithAutomaticExternalLinks
Returns a new instance of KramdownWithAutomaticExternalLinks.
24 25 26 27 |
# File 'lib/kramdown/parser/kramdown_with_automatic_external_links.rb', line 24 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
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/kramdown/parser/kramdown_with_automatic_external_links.rb', line 29 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/HandleExceptions rescue Addressable::URI::InvalidURIError # it's safe to ignore these very *specific* exceptions end # rubocop:enable Lint/HandleExceptions end super end |