Project

General

Profile

Feature #32424 » 0001-Add-setting-to-controll-the-hardbreaks-behaviour-fro.patch

Marius BĂLTEANU, 2021-08-12 00:13

View differences:

app/views/settings/_general.html.erb
19 19

  
20 20
<p><%= setting_select :protocol, [['HTTP', 'http'], ['HTTPS', 'https']] %></p>
21 21

  
22
<p><%= setting_select :text_formatting, Redmine::WikiFormatting.formats_for_select, :blank => :label_none %></p>
22
<p><%= setting_select :text_formatting, Redmine::WikiFormatting.formats_for_select, :blank => :label_none %>
23
  <span id="common_mark_info" class="<%= "hidden" unless Setting.text_formatting == "common_mark" %>">
24
    <label class="block">
25
      <%= check_box_tag(nil, '', Redmine::Configuration['common_mark_enable_hardbreaks'] === true, disabled: true) %>
26
      Hardbreaks
27
    </label>
28
    <em class="info">
29
      <%= l(:text_setting_config_change) %>
30
    </em>
31
  </span>
32
</p>
23 33

  
24 34
<p><%= setting_check_box :cache_formatted_text %></p>
25 35

  
......
32 42

  
33 43
<%= submit_tag l(:button_save) %>
34 44
<% end %>
45

  
46
<%= javascript_tag do %>
47
  $('#settings_text_formatting').on('change', function(e){
48
    const formatter = e.target.value;
49
    const parent_block = document.getElementById("common_mark_info");
50

  
51
    if (formatter == "common_mark") {
52
      parent_block.classList.remove('hidden');
53
    } else {
54
      parent_block.classList.add('hidden');
55
    }
56
  });
57
<% end %>
config/configuration.yml.example
224 224
  #avatar_server_url: https://www.gravatar.com        # default
225 225
  #avatar_server_url: https://seccdn.libravatar.org
226 226

  
227
  # Configure CommonMark hardbreaks behaviour
228
  #
229
  # allowed values: true, false
230
  # true: treats regular line break (\n) as hardbreaks
231
  # false: switches to default common mark where two or more spaces are required
232
  # common_mark_enable_hardbreaks: true
233

  
227 234
# specific configuration options for production environment
228 235
# that overrides the default ones
229 236
production:
config/locales/en.yml
1284 1284
  text_avatar_server_config_html: The current avatar server is <a href="%{url}">%{url}</a>. You can configure it in config/configuration.yml.
1285 1285
  text_no_subject: no subject
1286 1286
  text_allowed_queries_to_select: Public (to any users) queries only selectable
1287

  
1287
  text_setting_config_change: You can configure the behaviour in config/configuration.yml. Please restart the application after editing it.
1288 1288

  
1289 1289
  default_role_manager: Manager
1290 1290
  default_role_developer: Developer
lib/redmine/configuration.rb
24 24
    @defaults = {
25 25
      'avatar_server_url' => 'https://www.gravatar.com',
26 26
      'email_delivery' => nil,
27
      'max_concurrent_ajax_uploads' => 2
27
      'max_concurrent_ajax_uploads' => 2,
28
      'common_mark_enable_hardbreaks' => true
28 29
    }
29 30

  
30 31
    @config = nil
lib/redmine/wiki_formatting/common_mark/formatter.rb
43 43
        # https://github.com/gjtorikian/commonmarker#render-options
44 44
        commonmarker_render_options: [
45 45
          :UNSAFE
46
        ].freeze,
46
        ],
47 47
      }.freeze
48 48

  
49
      if Redmine::Configuration['common_mark_enable_hardbreaks'] === true
50
        PIPELINE_CONFIG[:commonmarker_render_options].push(:HARDBREAKS)
51
      end
52
      PIPELINE_CONFIG[:commonmarker_render_options].freeze
53

  
49 54
      MarkdownPipeline = HTML::Pipeline.new [
50 55
        MarkdownFilter,
51 56
        SanitizationFilter,
(23-23/26)