summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorGo MAEDA <maeda@farend.jp>2024-10-20 07:51:38 +0000
committerGo MAEDA <maeda@farend.jp>2024-10-20 07:51:38 +0000
commit5407fea87338e2de3fb4bbd8edcd671eed910a52 (patch)
treed362b785d363ec394c01747285dedc40d50f5430 /lib
parentd58c2a21eaf97a439c7adf061aa529e58fe51748 (diff)
downloadredmine-5407fea87338e2de3fb4bbd8edcd671eed910a52.tar.gz
redmine-5407fea87338e2de3fb4bbd8edcd671eed910a52.zip
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
Diffstat (limited to 'lib')
-rw-r--r--lib/redmine.rb5
-rw-r--r--lib/redmine/acts/mentionable.rb2
-rw-r--r--lib/redmine/preparation.rb1
-rw-r--r--lib/redmine/wiki_formatting/markdown/formatter.rb109
-rw-r--r--lib/redmine/wiki_formatting/markdown/helper.rb64
-rw-r--r--lib/redmine/wiki_formatting/markdown/html_parser.rb52
6 files changed, 1 insertions, 232 deletions
diff --git a/lib/redmine.rb b/lib/redmine.rb
index 63961614d..2edfa55e9 100644
--- a/lib/redmine.rb
+++ b/lib/redmine.rb
@@ -25,11 +25,6 @@ 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
# CommonMarker is not available
diff --git a/lib/redmine/acts/mentionable.rb b/lib/redmine/acts/mentionable.rb
index f8332637e..d0d33ddf7 100644
--- a/lib/redmine/acts/mentionable.rb
+++ b/lib/redmine/acts/mentionable.rb
@@ -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
diff --git a/lib/redmine/preparation.rb b/lib/redmine/preparation.rb
index 553f8693a..1aeb81e46 100644
--- a/lib/redmine/preparation.rb
+++ b/lib/redmine/preparation.rb
@@ -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
diff --git a/lib/redmine/wiki_formatting/markdown/formatter.rb b/lib/redmine/wiki_formatting/markdown/formatter.rb
deleted file mode 100644
index f2e7a6581..000000000
--- a/lib/redmine/wiki_formatting/markdown/formatter.rb
+++ /dev/null
@@ -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
diff --git a/lib/redmine/wiki_formatting/markdown/helper.rb b/lib/redmine/wiki_formatting/markdown/helper.rb
deleted file mode 100644
index e77547412..000000000
--- a/lib/redmine/wiki_formatting/markdown/helper.rb
+++ /dev/null
@@ -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
diff --git a/lib/redmine/wiki_formatting/markdown/html_parser.rb b/lib/redmine/wiki_formatting/markdown/html_parser.rb
deleted file mode 100644
index 6e16126d9..000000000
--- a/lib/redmine/wiki_formatting/markdown/html_parser.rb
+++ /dev/null
@@ -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