Project

General

Profile

Actions

Feature #38372

closed

Use Commonmarker instead of Redcarpet by default when rendering Markdown attachments

Added by Mizuki ISHIKAWA almost 2 years ago. Updated almost 2 years ago.

Status:
Closed
Priority:
Normal
Assignee:
Category:
Text formatting
Target version:
-
Start date:
Due date:
% Done:

0%

Estimated time:
Resolution:
Fixed

Description

markdown_formatter returns 'common_mark' only when text_formatting is common_mark, and 'markdown' otherwise.
For example, when you attach an markdown.md file and preview it in an environment where text_formatting is Textile, the contents of the file are converted to HTML by RedCarpet('markdown').

Since RedCarpet('markdown') was deprecated in #36807, why not change markdown_formatter to return 'markdown' only when text_formatting is markdown and 'cmmon_mark' otherwise?


Related issues

Related to Redmine - Patch #36807: Remove CommonMark experimental flag and mark as deprecated the RedCarpet MarkdownClosedMarius BÄ‚LTEANU

Actions
Actions #1

Updated by Mizuki ISHIKAWA almost 2 years ago

Attached is a patch to change the code.

diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb
index 43f32fbc72..3177d0eb7c 100644
--- a/app/helpers/application_helper.rb
+++ b/app/helpers/application_helper.rb
@@ -1855,10 +1855,10 @@ module ApplicationHelper
   # Returns the markdown formatter: markdown or common_mark
   # ToDo: Remove this when markdown will be removed
   def markdown_formatter
-    if Setting.text_formatting == "common_mark" 
-      "common_mark" 
-    else
+    if Setting.text_formatting == "markdown" 
       "markdown" 
+    else
+      "common_mark" 
     end
   end

diff --git a/test/helpers/application_helper_test.rb b/test/helpers/application_helper_test.rb
index fc0351885f..d5d73282d8 100644
--- a/test/helpers/application_helper_test.rb
+++ b/test/helpers/application_helper_test.rb
@@ -2229,6 +2229,19 @@ class ApplicationHelperTest < Redmine::HelperTest
     end
   end

+  def test_markdown_formatter
+    [
+      ['markdown', 'markdown'],
+      ['common_mark', 'common_mark'],
+      ['textile', 'common_mark'],
+      ['', 'common_mark']
+    ].each do |text_formatting, expected|
+      with_settings text_formatting: text_formatting do
+        assert_equal expected, markdown_formatter
+      end
+    end
+  end
+
   private

   def wiki_links_with_special_characters
Actions #2

Updated by Go MAEDA almost 2 years ago

  • Related to Patch #36807: Remove CommonMark experimental flag and mark as deprecated the RedCarpet Markdown added
Actions #3

Updated by Go MAEDA almost 2 years ago

  • Subject changed from Change the default for markdown_formatter from markdown to common_mark to Use Commonmarker instead of Redcarpet by default when rendering Markdown attachments
Actions #4

Updated by Go MAEDA almost 2 years ago

  • Status changed from New to Closed
  • Assignee set to Go MAEDA
  • Resolution set to Fixed

Committed the change as a part of #36807. Thank you.

Actions

Also available in: Atom PDF