Commit 590906c3 authored by nicolasdular's avatar nicolasdular

Allow styling broadcast messages

Adds the ability to style links in broadcast messages and use line
breaks to format messages.
parent 222e7033
---
title: Allow styling broadcast messages
merge_request: 21522
author:
type: added
# frozen_string_literal: true
module Banzai
module Filter
# Sanitize HTML produced by Markdown.
#
# Extends Banzai::Filter::BaseSanitizationFilter with specific rules.
class BroadcastMessageSanitizationFilter < Banzai::Filter::BaseSanitizationFilter
def customize_whitelist(whitelist)
whitelist[:elements].push('br')
whitelist[:attributes]['a'].push('class', 'style')
whitelist[:css] = { properties: %w(color border background padding margin text-decoration) }
whitelist
end
end
end
end
......@@ -6,7 +6,7 @@ module Banzai
def self.filters
@filters ||= FilterArray[
Filter::MarkdownFilter,
Filter::SanitizationFilter,
Filter::BroadcastMessageSanitizationFilter,
Filter::EmojiFilter,
Filter::ColorFilter,
......
# frozen_string_literal: true
require 'spec_helper'
describe Banzai::Pipeline::BroadcastMessagePipeline do
before do
stub_commonmark_sourcepos_disabled
end
subject { described_class.to_html(exp, project: spy) }
context "allows `a` elements" do
let(:exp) { "<a>Link</a>" }
it { is_expected.to eq("<p>#{exp}</p>") }
end
context "allows `br` elements" do
let(:exp) { "<a>Link</a>" }
it { is_expected.to eq("<p>#{exp}</p>") }
end
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment