Class: Decidim::ContentRenderers::LinkRenderer

Inherits:
BaseRenderer
  • Object
show all
Defined in:
lib/decidim/content_renderers/link_renderer.rb

Overview

A renderer that converts URLs to links and strips attributes in anchors.

Examples: ‘<a href=“urls.net” onmouseover=“alert(’hello’)”>URLs</a>‘ Gets rendered as: `<a href=“decidim.org” target=“_blank” rel=“noopener”>decidim.org</a>` And: `<a href=“javascript:document.cookies”>click me</a>` Gets rendered as: `click me`

Instance Attribute Summary

Attributes inherited from BaseRenderer

#content

Instance Method Summary collapse

Methods inherited from BaseRenderer

#initialize

Constructor Details

This class inherits a constructor from Decidim::ContentRenderers::BaseRenderer

Instance Method Details

#render(options = {}) ⇒ String

Returns the content ready to display (contains HTML).

Returns:

  • (String)

    the content ready to display (contains HTML)



19
20
21
22
23
24
# File 'lib/decidim/content_renderers/link_renderer.rb', line 19

def render(options = {})
  return content unless content.is_a?(String)

  options = { target: "_blank", rel: "nofollow noopener" }.merge(options)
  Anchored::Linker.auto_link(content, options)
end