Merge pull request #1778 from ClearlyClaire/glitch-soc/fixes/code-block-indentation

Fix leading spaces being stripped in Markdown code blocks
This commit is contained in:
Claire 2022-05-24 12:11:56 +02:00 committed by GitHub
commit c279dbd470
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 5 additions and 1 deletions

View file

@ -8,7 +8,7 @@ class AdvancedTextFormatter < TextFormatter
end end
def block_code(code, _language) def block_code(code, _language)
<<~HTML.squish <<~HTML
<pre><code>#{ERB::Util.h(code).gsub("\n", '<br/>')}</code></pre> <pre><code>#{ERB::Util.h(code).gsub("\n", '<br/>')}</code></pre>
HTML HTML
end end

View file

@ -40,6 +40,10 @@ RSpec.describe AdvancedTextFormatter do
it 'formats code using <pre> and <code>' do it 'formats code using <pre> and <code>' do
is_expected.to include '<pre><code>int main' is_expected.to include '<pre><code>int main'
end end
it 'does not strip leading spaces' do
is_expected.to include '> return 0'
end
end end
context 'given some quote' do context 'given some quote' do