Content processors

A content processor is a concept to refer to a set of two classes: a content parser class and a content renderer class.

The content parser class is used to process the text before it is saved to the database, and the associated renderer class is used to render the saved content.

How do I add a content processor?

Register the content processor in an initializer:

Decidim.content_processors += [:special_words]

This symbol will be used to instantiate parsers and processors using the following convention:

  • "Decidim::ContentParsers::#\{type.to_s.camelize}Parser"

  • "Decidim::ContentRenderers::#\{type.to_s.camelize}Renderer"

Autoload parser and renderer if in the lib/ dir. For example if in proposals module edit lib/decidim/proposals.rb:

module Decidim
  module ContentParsers
    autoload :ProposalParser, "decidim/content_parsers/proposal_parser"
  module ContentRenderers
    autoload :ProposalRenderer, "decidim/content_renderers/proposal_renderer"

Declare the parser class:

class Decidim::ContentParsers::SpecialWordsParser < BaseParser
  Metadata =

  def rewrite
    content.gsub('foo', '~~foo~~')

  def metadata'foo').size)

And the renderer class:

class Decidim::ContentRenderers::SpecialWordsRenderer < BaseRenderer
  def render
    content.gsub(/\~\~(.*?)\~\~/, '<del>\1</del>')

How to use the content parser class

parser =, {})
parser.rewrite # returns the content rewritten
parser.metadata # returns a Metadata object

How to use the content renderer class

renderer =
parser.render # returns the content formatted

Additional documentation

You can check the docs in the base classes and the user processor.