From fe65c0e44f4f8b05ce545eca8a429c1da162fc5a Mon Sep 17 00:00:00 2001 From: Claire Date: Tue, 24 May 2022 10:24:59 +0200 Subject: Fix leading spaces being stripped in Markdown code blocks Fixes #1776 --- app/lib/advanced_text_formatter.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/lib/advanced_text_formatter.rb b/app/lib/advanced_text_formatter.rb index 728400819..dcaf34b91 100644 --- a/app/lib/advanced_text_formatter.rb +++ b/app/lib/advanced_text_formatter.rb @@ -8,7 +8,7 @@ class AdvancedTextFormatter < TextFormatter end def block_code(code, _language) - <<~HTML.squish + <<~HTML
#{ERB::Util.h(code).gsub("\n", '
')}
HTML end -- cgit From 55ba907108df537e90f2ca08d9b1674ff8649eb8 Mon Sep 17 00:00:00 2001 From: Claire Date: Tue, 24 May 2022 10:26:04 +0200 Subject: Add test --- spec/lib/advanced_text_formatter_spec.rb | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/spec/lib/advanced_text_formatter_spec.rb b/spec/lib/advanced_text_formatter_spec.rb index ea1a9570d..3255fc927 100644 --- a/spec/lib/advanced_text_formatter_spec.rb +++ b/spec/lib/advanced_text_formatter_spec.rb @@ -40,6 +40,10 @@ RSpec.describe AdvancedTextFormatter do it 'formats code using
 and ' do
           is_expected.to include '
int main'
         end
+
+        it 'does not strip leading spaces' do
+          is_expected.to include '>  return 0'
+        end
       end
 
       context 'given some quote' do
-- 
cgit