Skip to content

Commit bb266c1

Browse files
CopilotPowerKiKi
andcommitted
Replace direct redcarpet usage with Redmine WikiFormatting system in redcarpet_filter.rb
Co-authored-by: PowerKiKi <[email protected]>
1 parent 0b7cb58 commit bb266c1

File tree

1 file changed

+14
-25
lines changed

1 file changed

+14
-25
lines changed

lib/redmine_git_hosting/redcarpet_filter.rb

Lines changed: 14 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -2,46 +2,35 @@
22

33
require 'html/pipeline/filter'
44
require 'html/pipeline/text_filter'
5-
require 'redcarpet'
6-
require 'rouge'
7-
require 'rouge/plugins/redcarpet'
85

96
module RedmineGitHosting
10-
class HTMLwithRouge < Redcarpet::Render::HTML
11-
include Rouge::Plugins::Redcarpet
12-
end
13-
147
class RedcarpetFilter < HTML::Pipeline::TextFilter
158
def initialize(text, context = nil, result = nil)
169
super text, context, result
1710
@text = @text.delete "\r"
1811
end
1912

20-
# Convert Markdown to HTML using the best available implementation
21-
# and convert into a DocumentFragment.
13+
# Convert Markdown to HTML using Redmine's WikiFormatting system
14+
# for consistency with Redmine's text formatting configuration.
2215
#
2316
def call
24-
html = self.class.renderer.render @text
17+
html = markdown_formatter.new(@text).to_html
2518
html.rstrip!
2619
html
2720
end
2821

29-
def self.renderer
30-
@renderer ||= Redcarpet::Markdown.new HTMLwithRouge, markdown_options
31-
end
22+
private
3223

33-
def self.markdown_options
34-
@markdown_options ||= {
35-
fenced_code_blocks: true,
36-
lax_spacing: true,
37-
strikethrough: true,
38-
autolink: true,
39-
tables: true,
40-
underline: true,
41-
highlight: true
42-
}.freeze
24+
def markdown_formatter
25+
# Find the markdown formatter from Redmine's WikiFormatting system
26+
formatter_name = Redmine::WikiFormatting.format_names.find { |name| name =~ /markdown/i }
27+
28+
if formatter_name
29+
Redmine::WikiFormatting.formatter_for(formatter_name)
30+
else
31+
# Fallback to textile formatter if no markdown formatter is available
32+
Redmine::WikiFormatting.formatter_for('textile')
33+
end
4334
end
44-
45-
private_class_method :markdown_options
4635
end
4736
end

0 commit comments

Comments
 (0)