Merge pull request #1070 from sgmap/fix_1014_html_in_annotations_privees
Fix 1014 html in annotations privees
This commit is contained in:
commit
c4498ece2b
3 changed files with 33 additions and 2 deletions
10
app/helpers/html_to_string_helper.rb
Normal file
10
app/helpers/html_to_string_helper.rb
Normal file
|
@ -0,0 +1,10 @@
|
|||
module HtmlToStringHelper
|
||||
def html_to_string(html)
|
||||
string_with_tags = html
|
||||
.gsub(/<br[ ]?[\/]?>/, "\n")
|
||||
.gsub('</p>', "\n")
|
||||
.gsub('<p>', '')
|
||||
|
||||
strip_tags(string_with_tags)
|
||||
end
|
||||
end
|
|
@ -1,7 +1,7 @@
|
|||
= render partial: 'new_gestionnaire/dossiers/champs/champ_label', locals: { form: form, champ: champ }
|
||||
|
||||
= form.text_area :value,
|
||||
~ form.text_area :value,
|
||||
row: 6,
|
||||
placeholder: champ.description,
|
||||
required: champ.mandatory,
|
||||
value: sanitize(champ.value)
|
||||
value: html_to_string(champ.value)
|
||||
|
|
21
spec/helpers/html_to_string_helper_spec.rb
Normal file
21
spec/helpers/html_to_string_helper_spec.rb
Normal file
|
@ -0,0 +1,21 @@
|
|||
describe HtmlToStringHelper do
|
||||
describe "#html_to_string" do
|
||||
describe 'does not change plain text' do
|
||||
it { expect(helper.html_to_string('text')).to eq('text') }
|
||||
end
|
||||
|
||||
describe 'deals with <br>' do
|
||||
it { expect(helper.html_to_string('new<br>line')).to eq("new\nline") }
|
||||
it { expect(helper.html_to_string('new<br/>line')).to eq("new\nline") }
|
||||
it { expect(helper.html_to_string('new<br />line')).to eq("new\nline") }
|
||||
end
|
||||
|
||||
describe 'deals with <p>' do
|
||||
it { expect(helper.html_to_string('<p>p1</p><p>p2</p>')).to eq("p1\np2\n") }
|
||||
end
|
||||
|
||||
describe 'strip other tags' do
|
||||
it { expect(helper.html_to_string('<i>italic</i>')).to eq('italic') }
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Reference in a new issue