From 2c520d9975d4883ed401a39be7fbc00385c87c14 Mon Sep 17 00:00:00 2001 From: Henne Vogelsang Date: Mon, 5 Jul 2021 21:56:25 +0200 Subject: [PATCH] Switch to fenced code blocks in markdown `:fenced_code_blocks:` Blocks delimited with 3 or more ~ or backticks will be considered as code, without the need to be indented. An optional language name may be added at the end of the opening fence for the code block. `:disable_indented_code_blocks:` Do not parse usual markdown code blocks. Markdown converts text with four spaces at the front of each line to code blocks. This option prevents it from doing so. Recommended to use with fenced_code_blocks: true. Fixes #2764 --- app/helpers/format_helper.rb | 8 +++++--- spec/helpers/format_helper_spec.rb | 2 +- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/app/helpers/format_helper.rb b/app/helpers/format_helper.rb index b0691518..f4110755 100644 --- a/app/helpers/format_helper.rb +++ b/app/helpers/format_helper.rb @@ -191,9 +191,11 @@ module FormatHelper return '' if text.nil? options = { - autolink: true, - space_after_headers: true, - no_intra_emphasis: true + autolink: true, + space_after_headers: true, + no_intra_emphasis: true, + fenced_code_blocks: true, + disable_indented_code_blocks: true } markdown = Redcarpet::Markdown.new(Redcarpet::Render::HTML.new(escape_html: escape_html), options) markdown.render(text).html_safe diff --git a/spec/helpers/format_helper_spec.rb b/spec/helpers/format_helper_spec.rb index 0eb4d055..11c241bc 100644 --- a/spec/helpers/format_helper_spec.rb +++ b/spec/helpers/format_helper_spec.rb @@ -11,7 +11,7 @@ describe FormatHelper, type: :helper do it 'should return HTML for header markdown' do expect(Redcarpet::Markdown).to receive(:new) - .with(Redcarpet::Render::HTML, autolink: true, space_after_headers: true, no_intra_emphasis: true) + .with(Redcarpet::Render::HTML, autolink: true, space_after_headers: true, no_intra_emphasis: true, fenced_code_blocks: true, disable_indented_code_blocks: true) .and_call_original expect(markdown('# this is my header')).to eq "

this is my header

\n"