Project

General

Profile

Feature #32424 » configuration-setting-for-hardbreaks.patch

Marius BĂLTEANU, 2021-07-28 00:19

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
    <em class="info">
25
        <strong>Hardbreaks:</strong> <%= Redmine::Configuration['common_mark_enable_hardbreaks'] === true ? l(:label_enabled) : l(:label_disabled) %>.
26
    </em>
27
    <em class="info">
28
      You can configure the behaviour in config/configuration.yml. Please restart the application after editing it.
29
    </em>
30
  </span>
31
</p>
23 32

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

  
......
32 41

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

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

  
50
    if (formatter == "common_mark") {
51
      parent_block.classList.remove('hidden');
52
    } else {
53
      parent_block.classList.add('hidden');
54
    }
55
  });
56
<% 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
893 893
  label_copied_to: Copied to
894 894
  label_copied_from: Copied from
895 895
  label_stay_logged_in: Stay logged in
896
  label_enabled: enabled
896 897
  label_disabled: disabled
897 898
  label_optional: optional
898 899
  label_show_completed_versions: Show completed versions
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,
(22-22/26)