Drop deprecated Redcarpet based Markdown formatter (#40149).

Patch by Go MAEDA (user:maeda).


git-svn-id: https://svn.redmine.org/redmine/trunk@23153 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
Go MAEDA
2024-10-20 07:51:38 +00:00
parent d58c2a21ea
commit 5407fea873
50 changed files with 24 additions and 7626 deletions

View File

@@ -24,11 +24,6 @@ begin
rescue LoadError
# MiniMagick is not available
end
begin
require 'redcarpet' unless Object.const_defined?(:Redcarpet)
rescue LoadError
# Redcarpet is not available
end
begin
require 'commonmarker' unless Object.const_defined?(:CommonMarker)
rescue LoadError

View File

@@ -86,7 +86,7 @@ module Redmine
case text_formatting
when 'textile'
content = content.gsub(%r{<pre>(.*?)</pre>}m, '')
when 'markdown', 'common_mark'
when 'common_mark'
content = content.gsub(%r{(~~~|```)(.*?)(~~~|```)}m, '')
end

View File

@@ -408,7 +408,6 @@ module Redmine
WikiFormatting.map do |format|
format.register :textile
format.register :markdown, label: 'Markdown (deprecated)' if Object.const_defined?(:Redcarpet)
if Object.const_defined?(:CommonMarker)
format.register :common_mark, label: 'CommonMark Markdown (GitHub Flavored)'
end

View File

@@ -1,109 +0,0 @@
# frozen_string_literal: true
# Redmine - project management software
# Copyright (C) 2006- Jean-Philippe Lang
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
require 'cgi'
module Redmine
module WikiFormatting
module Markdown
class HTML < Redcarpet::Render::HTML
include ActionView::Helpers::TagHelper
include Redmine::Helpers::URL
def autolink(link, link_type)
if link_type == :email
link("mailto:#{link}", nil, link) || CGI.escapeHTML(link)
else
content = link
# Pretty printing: if we get an email address as an actual URI, e.g.
# `mailto:foo@bar.com`, we don't want to print the `mailto:` prefix
content = link[7..-1] if link.start_with?('mailto:')
link(link, nil, content) || CGI.escapeHTML(link)
end
end
def link(link, title, content)
return nil unless uri_with_link_safe_scheme?(link)
css = nil
unless link&.starts_with?('/') || link&.starts_with?('mailto:')
css = 'external'
end
content_tag('a', content.to_s.html_safe, :href => link, :title => title, :class => css)
end
def block_code(code, language)
if language.present? && Redmine::SyntaxHighlighting.language_supported?(language)
html = Redmine::SyntaxHighlighting.highlight_by_language(code, language)
classattr = " class=\"#{CGI.escapeHTML language} syntaxhl\""
else
html = CGI.escapeHTML(code)
end
# original language for extension development
langattr = " data-language=\"#{CGI.escapeHTML language}\"" if language.present?
"<pre><code#{classattr}#{langattr}>#{html}</code></pre>"
end
def image(link, title, alt_text)
return unless uri_with_safe_scheme?(link)
tag('img', :src => link, :alt => alt_text || "", :title => title)
end
end
class Formatter
include Redmine::WikiFormatting::LinksHelper
include Redmine::WikiFormatting::SectionHelper
alias :inline_restore_redmine_links :restore_redmine_links
def initialize(text)
@text = text
end
def to_html(*args)
html = formatter.render(@text)
html = inline_restore_redmine_links(html)
html
end
private
def formatter
@@formatter ||= Redcarpet::Markdown.new(
Redmine::WikiFormatting::Markdown::HTML.new(
:filter_html => true,
:hard_wrap => true
),
:autolink => true,
:fenced_code_blocks => true,
:space_after_headers => true,
:tables => true,
:strikethrough => true,
:superscript => true,
:no_intra_emphasis => true,
:footnotes => true,
:lax_spacing => true,
:underline => true
)
end
end
end
end
end

View File

@@ -1,64 +0,0 @@
# frozen_string_literal: true
# Redmine - project management software
# Copyright (C) 2006- Jean-Philippe Lang
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
module Redmine
module WikiFormatting
module Markdown
module Helper
def wikitoolbar_for(field_id, preview_url = preview_text_path)
heads_for_wiki_formatter
javascript_tag(
"var wikiToolbar = new jsToolBar(document.getElementById('#{field_id}')); " \
"wikiToolbar.setHelpLink('#{escape_javascript help_wiki_syntax_path}'); " \
"wikiToolbar.setPreviewUrl('#{escape_javascript preview_url}'); " \
"wikiToolbar.draw();"
)
end
def initial_page_content(page)
"# #{page.pretty_title}"
end
def heads_for_wiki_formatter
unless @heads_for_wiki_formatter_included
toolbar_language_options = User.current && User.current.pref.toolbar_language_options
lang =
if toolbar_language_options.nil?
UserPreference::DEFAULT_TOOLBAR_LANGUAGE_OPTIONS
else
toolbar_language_options.split(',')
end
content_for :header_tags do
javascript_include_tag('jstoolbar/jstoolbar') +
javascript_include_tag('jstoolbar/markdown') +
javascript_include_tag("jstoolbar/lang/jstoolbar-#{current_language.to_s.downcase}") +
javascript_tag(
"var wikiImageMimeTypes = #{Redmine::MimeType.by_type('image').to_json};" \
"var userHlLanguages = #{lang.to_json};"
) +
stylesheet_link_tag('jstoolbar')
end
@heads_for_wiki_formatter_included = true
end
end
end
end
end
end

View File

@@ -1,52 +0,0 @@
# frozen_string_literal: true
# Redmine - project management software
# Copyright (C) 2006- Jean-Philippe Lang
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
module Redmine
module WikiFormatting
module Markdown
class HtmlParser < Redmine::WikiFormatting::HtmlParser
self.tags = tags.merge(
'b' => {:pre => '**', :post => '**'},
'strong' => {:pre => '**', :post => '**'},
'i' => {:pre => '*', :post => '*'},
'em' => {:pre => '*', :post => '*'},
'u' => {:pre => '_', :post => '_'},
'strike' => {:pre => '~~', :post => '~~'},
'h1' => {:pre => "\n\n# ", :post => "\n\n"},
'h2' => {:pre => "\n\n## ", :post => "\n\n"},
'h3' => {:pre => "\n\n### ", :post => "\n\n"},
'h4' => {:pre => "\n\n#### ", :post => "\n\n"},
'h5' => {:pre => "\n\n##### ", :post => "\n\n"},
'h6' => {:pre => "\n\n###### ", :post => "\n\n"},
'th' => {:pre => '*', :post => "*\n"},
'td' => {:pre => '', :post => "\n"},
'a' => lambda do |node|
if node.content.present? && node.attributes.key?('href')
%| [#{node.content}](#{node.attributes['href'].value}) |
elsif node.attributes.key?('href')
%| #{node.attributes['href'].value} |
else
node.content
end
end
)
end
end
end
end