Project

General

Profile

Feature #32424 » 0001-Add-setting-in-admin-to-control-the-hardbreaks-behav.patch

Marius BĂLTEANU, 2021-09-04 13:21

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>
23
  <%= setting_select :text_formatting, Redmine::WikiFormatting.formats_for_select, :blank => :label_none %>
24
  <label id="common_mark_settings" class="block <%= "hidden" unless Setting.text_formatting == "common_mark" %>">
25
    <%= setting_check_box :text_formatting_common_mark_hardbreaks, label: false %>
26
    <%= l(:setting_text_formatting_common_mark_hardbreaks) %>
27
  </label>
28
</p>
23 29

  
24 30
<p><%= setting_check_box :cache_formatted_text %></p>
25 31

  
......
32 38

  
33 39
<%= submit_tag l(:button_save) %>
34 40
<% end %>
41

  
42
<%= javascript_tag do %>
43
  $('#settings_text_formatting').on('change', function(e){
44
    const formatter = e.target.value;
45
    const settings = document.getElementById("common_mark_settings");
46
    if (formatter == "common_mark") {
47
      settings.classList.remove('hidden');
48
    } else {
49
      settings.classList.add('hidden');
50
    }
51
  });
52
<% end %>
config/locales/en.yml
510 510
  setting_project_list_defaults: Projects list defaults
511 511
  setting_twofa: Two-factor authentication
512 512
  setting_default_issue_query: Default Query
513
  setting_text_formatting_common_mark_hardbreaks: "Use regular line breaks (\\n) as hardbreaks"
513 514

  
514 515
  permission_add_project: Create project
515 516
  permission_add_subprojects: Create subprojects
config/settings.yml
96 96
  default: 0
97 97
text_formatting:
98 98
  default: textile
99
text_formatting_common_mark_hardbreaks:
100
  default: 1
99 101
cache_formatted_text:
100 102
  default: 0
101 103
wiki_compression:
lib/redmine/wiki_formatting/common_mark/formatter.rb
42 42

  
43 43
        # https://github.com/gjtorikian/commonmarker#render-options
44 44
        commonmarker_render_options: [
45
          :HARDBREAKS,
46 45
          :UNSAFE
47
        ].freeze,
46
        ],
48 47
      }.freeze
49 48

  
50 49
      MarkdownPipeline = HTML::Pipeline.new [
......
57 56

  
58 57
      class Formatter < Redmine::WikiFormatting::Markdown::Formatter
59 58
        def to_html(*args)
59
          if Setting.text_formatting_common_mark_hardbreaks?
60
            PIPELINE_CONFIG[:commonmarker_render_options].push(:HARDBREAKS) unless PIPELINE_CONFIG[:commonmarker_render_options].include?(:HARDBREAKS)
61
          else
62
            PIPELINE_CONFIG[:commonmarker_render_options].delete(:HARDBREAKS) if PIPELINE_CONFIG[:commonmarker_render_options].include?(:HARDBREAKS)
63
          end
64

  
60 65
          result = MarkdownPipeline.call @text
61 66
          result[:output].to_s
62 67
        end
public/stylesheets/application.css
849 849
  float: none;
850 850
}
851 851

  
852
.tabular label.block.hidden {
853
  display: none;
854
}
855

  
852 856
.tabular label.inline{
853 857
  font-weight: normal;
854 858
  float:none;
(24-24/26)