Skip to content

OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub

Remove pandoc and option to migrate from textile

Oliver Günthere08203c8c4f1
diff --git a/Gemfile b/Gemfile
index f0a283d74d9..605a40c64e8 100644
--- a/Gemfile
+++ b/Gemfile
@@ -114,9 +114,6 @@ gem 'mail', '= 2.8.1'
# provide compatible filesystem information for available storage
gem 'sys-filesystem', '~> 1.4.0', require: false
-# Faster posix-compliant spawns for 8.0. conversions with pandoc
-gem 'posix-spawn', '~> 0.3.13', require: false
-
gem 'bcrypt', '~> 3.1.6'
gem 'multi_json', '~> 1.15.0'
diff --git a/Gemfile.lock b/Gemfile.lock
index a455a2a6dc8..29552ab4184 100644
--- a/Gemfile.lock
+++ b/Gemfile.lock
@@ -691,7 +691,6 @@ GEM
activesupport (> 2.2.1)
nokogiri (~> 1.10, >= 1.10.4)
rubyzip (>= 1.2.0)
- posix-spawn (0.3.15)
prawn (2.4.0)
pdf-core (~> 0.9.0)
ttfunk (~> 1.7)
@@ -1113,7 +1112,6 @@ DEPENDENCIES
pdf-inspector (~> 1.2)
pg (~> 1.5.0)
plaintext (~> 0.3.2)
- posix-spawn (~> 0.3.13)
prawn (~> 2.2)
primer_view_components!
pry-byebug (~> 3.10.0)
diff --git a/db/migrate/20180706150714_convert_to_markdown.rb b/db/migrate/20180706150714_convert_to_markdown.rb
index af6e0aa73cc..216461c2116 100644
--- a/db/migrate/20180706150714_convert_to_markdown.rb
+++ b/db/migrate/20180706150714_convert_to_markdown.rb
@@ -50,10 +50,12 @@ class ConvertToMarkdown < ActiveRecord::Migration[5.1]
end
if setting && setting[0] == 'textile'
- converter = OpenProject::TextFormatting::Formats::Markdown::TextileConverter.new
- converter.run!
- end
+ raise <<~ERROR
+ You appear to be upgrading from an old version of OpenProject using textile text formatters.
- Setting.where(name: %w(text_formatting use_wysiwyg)).delete_all
+ OpenProject version 13.0 no longer provides the migration from Textile to Markdown.
+ First upgrade to any 12.x version, before performing the upgrade to 13.0
+ ERROR
+ end
end
end
diff --git a/docker/ci/Dockerfile b/docker/ci/Dockerfile
index a0a5f66be62..94565dc3a15 100644
--- a/docker/ci/Dockerfile
+++ b/docker/ci/Dockerfile
@@ -32,7 +32,7 @@ RUN echo "deb http://apt.postgresql.org/pub/repos/apt buster-pgdg main" > /etc/a
RUN --mount=type=cache,target=/var/cache/apt \
apt-get update -qq && apt-get install -y \
- postgresql-13 postgresql-client-13 time pandoc imagemagick default-jre-headless firefox-esr
+ postgresql-13 postgresql-client-13 time imagemagick default-jre-headless firefox-esr
ENV CHROME_SOURCE_URL="https://dl.google.com/dl/linux/direct/google-chrome-stable_current_amd64.deb"
RUN f="/tmp/chrome.deb"; wget --no-verbose -O $f $CHROME_SOURCE_URL && apt install -y $f && rm -f $f
diff --git a/docker/prod/setup/preinstall-common.sh b/docker/prod/setup/preinstall-common.sh
index 5106fe89ea4..1d50baca72b 100755
--- a/docker/prod/setup/preinstall-common.sh
+++ b/docker/prod/setup/preinstall-common.sh
@@ -38,7 +38,6 @@ fi
apt-get update -qq
apt-get install -y \
apt-transport-https \
- pandoc \
poppler-utils \
unrtf \
tesseract-ocr \
diff --git a/docs/installation-and-operations/misc/textile-migration/README.md b/docs/installation-and-operations/misc/textile-migration/README.md
index c1378f57ea8..695f443d88c 100644
--- a/docs/installation-and-operations/misc/textile-migration/README.md
+++ b/docs/installation-and-operations/misc/textile-migration/README.md
@@ -10,6 +10,7 @@ All instances that have run OpenProject prior to 8.0.0. must be converted in ord
The migration will be performed automatically during your upgrade to 8.0. You will find additional information to prevent or postpone the migration down below.
+You need to run this migration on an OpenProject version < 13.0, as the conversion migration is no longer part of OpenProject starting that version.
## Dependencies
diff --git a/lib/open_project/text_formatting/formats/markdown/pandoc_downloader.rb b/lib/open_project/text_formatting/formats/markdown/pandoc_downloader.rb
deleted file mode 100644
index bdfbc365094..00000000000
--- a/lib/open_project/text_formatting/formats/markdown/pandoc_downloader.rb
+++ /dev/null
@@ -1,129 +0,0 @@
-#-- copyright
-# OpenProject is an open source project management software.
-# Copyright (C) 2012-2023 the OpenProject GmbH
-#
-# This program is free software; you can redistribute it and/or
-# modify it under the terms of the GNU General Public License version 3.
-#
-# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
-# Copyright (C) 2006-2013 Jean-Philippe Lang
-# Copyright (C) 2010-2013 the ChiliProject Team
-#
-# 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.
-#
-# See COPYRIGHT and LICENSE files for more details.
-#++
-
-require 'open3'
-require 'fileutils'
-require 'rest-client'
-
-module OpenProject::TextFormatting::Formats
- module Markdown
- module PandocDownloader
- class << self
- def check_or_download!
- # Return if we have another version defined in ENV
- if forced_pandoc_path
- return compatible? forced_pandoc_path,
- "Environment variable OPENPROJECT_PANDOC_PATH set, but version is not executable by OpenProject or incompatible."
- end
-
- # Return if we have a compatible version
- return if compatible?
-
- warn <<~INFO
- You have no compatible (>= 2.0) of pandoc in path. We're now trying to download a recent version for your amd64 linux
- from '#{pandoc_amd64_tar}' to '#{vendored_pandoc_dir}'.
-
- For more information, please visit this page: https://www.openproject.org/textile-to-markdown-migration
- INFO
-
- download!
-
- raise "Failed to download pandoc version" unless compatible?
- rescue StandardError => e
- warn <<~WARNING
- Error occurred while trying to find / download compatible pandoc version for your system:
-
- #{e.message}
- WARNING
- end
-
- ##
- # Check if the given pandoc version is compatible
- # Returns true/false
- # Raises raise_msg if set and incompatible
- def compatible?(path = pandoc_path, raise_msg = nil)
- stdout, _, status = Open3.capture3(path, '--version')
-
- if !status.success? && raise_msg.present?
- raise raise_msg
- end
-
- status.success? && stdout.match(/^pandoc [23]\./i)
- rescue StandardError => e
- if raise_msg.present?
- raise raise_msg
- end
-
- false
- end
-
- def forced_pandoc_path
- ENV.fetch('OPENPROJECT_PANDOC_PATH', nil)
- end
-
- def pandoc_path
- vendored = Rails.root.join('vendor/pandoc/bin/pandoc').to_s
-
- # Always return the vendored path if we have installed one
- return vendored if File.executable?(vendored)
-
- ENV.fetch('OPENPROJECT_PANDOC_PATH', 'pandoc')
- end
-
- def vendored_pandoc_dir
- Rails.root.join('vendor/pandoc').to_s
- end
-
- def pandoc_amd64_tar
- ENV.fetch('OPENPROJECT_PANDOC_TAR_DOWNLOAD', 'https://github.com/jgm/pandoc/releases/download/2.2.3.2/pandoc-2.2.3.2-linux.tar.gz')
- end
-
- private
-
- def download!
- response = RestClient::Request.execute method: :get,
- url: pandoc_amd64_tar,
- raw_response: true
- tempfile = response.file
-
- # Create vendor dir, this will however usually exist already
- FileUtils.mkdir_p vendored_pandoc_dir
-
- begin
- # Extract downloaded tar into vendor
- _, stderr_str, status = Open3.capture3('tar', 'xvzf', tempfile.path.to_s,
- '--strip-components', '1', '-C', vendored_pandoc_dir)
- raise stderr_str unless status.success?
- ensure
- tempfile.unlink
- end
- end
- end
- end
- end
-end
diff --git a/lib/open_project/text_formatting/formats/markdown/pandoc_wrapper.rb b/lib/open_project/text_formatting/formats/markdown/pandoc_wrapper.rb
deleted file mode 100644
index 24b8ff91067..00000000000
--- a/lib/open_project/text_formatting/formats/markdown/pandoc_wrapper.rb
+++ /dev/null
@@ -1,139 +0,0 @@
-#-- copyright
-# OpenProject is an open source project management software.
-# Copyright (C) 2012-2023 the OpenProject GmbH
-#
-# This program is free software; you can redistribute it and/or
-# modify it under the terms of the GNU General Public License version 3.
-#
-# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
-# Copyright (C) 2006-2013 Jean-Philippe Lang
-# Copyright (C) 2010-2013 the ChiliProject Team
-#
-# 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.
-#
-# See COPYRIGHT and LICENSE files for more details.
-#++
-
-require 'posix-spawn'
-
-module OpenProject::TextFormatting::Formats
- module Markdown
- class PandocWrapper
- attr_reader :logger
-
- def initialize(logger = ::ActiveSupport::Logger.new(STDOUT))
- @logger = logger
- end
-
- def execute!(stdin)
- PandocDownloader.check_or_download!
- run_pandoc! pandoc_arguments, stdin_data: stdin
- end
-
- def check_arguments!
- PandocDownloader.check_or_download!
- wrap_mode
- read_output_formats
- end
-
- def pandoc_arguments
- [
- wrap_mode,
- '--atx-headers',
- '-f',
- 'textile',
- '-t',
- 'commonmark'
- ]
- end
-
- ##
- # Detect available wrap mode
- # --wrap=preserve will keep the wrapping the same, however is only available in versions 1.16+
- # In older versions we try to use the deprecated --no-wrap instead
- # --atx-headers will lead to headers like `### Some header` and '## Another header'
- def wrap_mode
- @wrap_mode ||= begin
- usage = read_usage_string
-
- # Detect wrap usage
- if usage.include? '--wrap='
- '--wrap=preserve'
- elsif usage.include? '--no-wrap'
- '--no-wrap'
- else
- err = 'Your pandoc version has neither --no-wrap nor --wrap=preserve. Please install a recent version of pandoc.'
- logger.error err
- raise err
- end
- end
- end
-
- def pandoc_timeout
- ENV.fetch('OPENPROJECT_PANDOC_TIMEOUT_SECONDS', 30).to_i
- end
-
- private
-
- ##
- # Run pandoc through posix-spawn and raise if an exception occurred
- def run_pandoc!(command, stdin_data: nil, timeout: pandoc_timeout)
- child = POSIX::Spawn::Child.new(PandocDownloader.pandoc_path, *command, input: stdin_data, timeout:)
- status = child.status
-
- unless status.success?
- code = status.exitstatus || 'unknown status (killed?)'
- termsig = status.termsig || 'none'
- stopsig = status.stopsig || 'none'
- signal_msg =
- if status.signaled?
- "Process received signal (term #{termsig}, stop #{stopsig})"
- else
- "Process did not receive signal"
- end
-
- out = (child.out || '').force_encoding('UTF-8').truncate(100)
- err = (child.err || '').force_encoding('UTF-8')
- raise <<~ERRORSTR
- Pandoc failed with code [#{code}] [Stopped=#{status.stopped?}]
- #{signal_msg}
- #{' '}
- #{out}
- #{err}
- ERRORSTR
- end
-
- # posix-spawn forces binary output, however pandoc
- # only works with UTF-8
- child.out.force_encoding('UTF-8')
- rescue POSIX::Spawn::TimeoutExceeded => e
- raise Timeout::Error, "Timeout occurred while running pandoc: #{e.message}"
- end
-
- def read_usage_string
- run_pandoc! %w[--help]
- end
-
- def read_output_formats
- @output_formats ||= begin
- run_pandoc! %w[--list-output-formats]
- rescue StandardError => e
- logger.warn "Failed to detect output format (Error was: #{e}). Falling back to github_markdown"
- ''
- end
- end
- end
- end
-end
diff --git a/lib/open_project/text_formatting/formats/markdown/textile_converter.rb b/lib/open_project/text_formatting/formats/markdown/textile_converter.rb
deleted file mode 100644
index 7c5ff4e84b7..00000000000
--- a/lib/open_project/text_formatting/formats/markdown/textile_converter.rb
+++ /dev/null
@@ -1,518 +0,0 @@
-#-- copyright
-# OpenProject is an open source project management software.
-# Copyright (C) 2012-2023 the OpenProject GmbH
-#
-# This program is free software; you can redistribute it and/or
-# modify it under the terms of the GNU General Public License version 3.
-#
-# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
-# Copyright (C) 2006-2013 Jean-Philippe Lang
-# Copyright (C) 2010-2013 the ChiliProject Team
-#
-# 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.
-#
-# See COPYRIGHT and LICENSE files for more details.
-#++
-
-# This file is derived from the 'Redmine converter from Textile to Markown'
-# https://github.com/Ecodev/redmine_convert_textile_to_markown
-#
-# Original license:
-# Copyright (c) 2016
-#
-# Permission is hereby granted, free of charge, to any person obtaining a copy
-# of this software and associated documentation files (the "Software"), to deal
-# in the Software without restriction, including without limitation the rights
-# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-# copies of the Software, and to permit persons to whom the Software is
-# furnished to do so, subject to the following conditions:
-#
-# The above copyright notice and this permission notice shall be included in all
-# copies or substantial portions of the Software.
-#
-# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
-# SOFTWARE.
-
-require 'ruby-progressbar'
-
-module OpenProject::TextFormatting::Formats
- module Markdown
- class TextileConverter
- include ActionView::Helpers::TagHelper
-
- TAG_CODE = 'pandoc-unescaped-single-backtick'.freeze
- TAG_FENCED_CODE_BLOCK = 'force-pandoc-to-ouput-fenced-code-block'.freeze
- DOCUMENT_BOUNDARY = "TextileConverterDocumentBoundary09339cab-f4f4-4739-85b0-d02ba1f342e6".freeze
- BLOCKQUOTE_START = "TextileConverterBlockquoteStart09339cab-f4f4-4739-85b0-d02ba1f342e6".freeze
- BLOCKQUOTE_END = "TextileConverterBlockquoteEnd09339cab-f4f4-4739-85b0-d02ba1f342e6".freeze
-
- attr_reader :pandoc, :logger
-
- def initialize
- @logger = ::OpenProject::Logging::TeeLogger.new 'markdown-migration'
- @pandoc = PandocWrapper.new logger
- end
-
- def run!
- # We're going to decrease the AR logger to avoid dumping all SQL inserts
- # in the output logs
- current_ar_log_level = ActiveRecord::Base.logger.level
-
- begin
- logger.info 'Starting conversion of Textile fields to CommonMark.'
-
- logger.info 'Decreasing ActiveRecord logger to avoid flooding your logs.'
- ActiveRecord::Base.logger.level = :error
-
- logger.info 'Checking compatibility of your installed pandoc version.'
- pandoc.check_arguments!
-
- ActiveRecord::Base.transaction do
- converters.each(&:call)
- end
-
- logger.info "\n-- Completed --"
- ensure
- ActiveRecord::Base.logger.level = current_ar_log_level
- end
- end
-
- private
-
- def converters
- [
- method(:convert_settings),
- method(:convert_models),
- method(:convert_custom_field_longtext)
- ]
- end
-
- def convert_settings
- logger.info 'Converting settings '
- Setting.welcome_text = convert_textile_to_markdown(Setting.welcome_text)
-
- Setting.registration_footer = Setting.registration_footer.dup.tap do |footer|
- footer.transform_values { |val| convert_textile_to_markdown(val) }
- end
- end
-
- ##
- # Converting model attributes as defined in +models_to_convert+.
- def convert_models
- models_to_convert.each do |klass, attributes|
- logger.info "Converting #{klass.name.pluralize} "
-
- # Iterate in batches to avoid plucking too much
- with_original_values_in_batches(klass, attributes) do |orig_values|
- markdowns_in_groups = bulk_convert_textile_with_fallback(klass, orig_values, attributes)
- new_values = new_values_for(attributes, orig_values, markdowns_in_groups)
-
- next if new_values.empty?
-
- ActiveRecord::Base.connection.execute(batch_update_statement(klass, attributes, new_values))
- end
- end
- end
-
- def convert_custom_field_longtext
- formattable_cfs = CustomField.where(field_format: 'text').pluck(:id)
- logger.info "CustomField type text "
- scope = CustomValue.where(custom_field_id: formattable_cfs)
- progress = ProgressBar.create(title: "Formattable CustomValues", total: scope.count)
- scope.in_batches(of: 200) do |relation|
- relation.pluck(:id, :value).each do |cv_id, value|
- CustomValue.where(id: cv_id).update_all(value: convert_textile_to_markdown(value))
- progress.increment
- end
- end
- progress.finish
- end
-
- # Iterate in batches to avoid plucking too much
- def with_original_values_in_batches(klass, attributes)
- batches_of_objects_to_convert(klass, attributes) do |relation, progress|
- orig_values = relation.pluck(:id, *attributes)
-
- result = yield orig_values
- progress.progress += orig_values.count
-
- result
- end
- end
-
- def bulk_convert_textile_with_fallback(klass, orig_values, attributes)
- old_values = orig_values.inject([]) do |former_values, values|
- former_values + values.drop(1)
- end
-
- joined_textile = concatenate_textile(old_values)
-
- markdowns_in_groups = []
-
- begin
- markdown = convert_textile_to_markdown(joined_textile, raise_on_timeout: true)
- markdowns_in_groups = split_markdown(markdown).each_slice(attributes.length).to_a
- rescue StandardError => e
- # Don't do anything. Let the subsequent code try to handle it again
- end
-
- if markdowns_in_groups.length != orig_values.length
- # Error handling: Some textile seems to be malformed e.g. <pre>something</pre (without closing >).
- # In such cases, handle texts individually to avoid the error affecting other texts
- progress = ProgressBar.create(title: "Converting items individually due to pandoc mismatch", total: orig_values.length)
- markdowns = old_values.each_with_index.map do |old_value, index|
- convert_textile_to_markdown(old_value, raise_on_timeout: false)
- rescue StandardError
- logger.error "Failing to convert single document #{klass.name} ##{orig_values[index].first}. "
- non_convertible_textile_doc(old_value)
- ensure
- progress.increment
- end
-
- markdowns_in_groups = markdowns.each_slice(attributes.length).to_a
- progress.finish
- end
-
- markdowns_in_groups
- end
-
- def new_values_for(attributes, orig_values, markdowns_in_groups)
- new_values = []
- orig_values.each_with_index do |values, index|
- new_values << { id: values[0] }.merge(attributes.zip(markdowns_in_groups[index]).to_h)
- end
-
- new_values
- end
-
- def convert_textile_to_markdown(textile, raise_on_timeout: false)
- return '' unless textile.present?
-
- cleanup_before_pandoc(textile)
-
- markdown = execute_pandoc_with_stdin! textile, raise_on_timeout
-
- if markdown.empty?
- markdown
- else
- cleanup_after_pandoc(markdown)
- end
- end
-
- def execute_pandoc_with_stdin!(textile, raise_on_timeout)
- pandoc.execute! textile
- rescue Timeout::Error => e
- if raise_on_timeout
- logger.error <<~TIMEOUT_WARN
- Execution of pandoc timed out: #{e}.
-
- You may want to increase the timeout
- (OPENPROJECT_PANDOC_TIMEOUT_SECONDS, currently at #{pandoc.pandoc_timeout} seconds)
- TIMEOUT_WARN
-
- raise e
- else
- logger.error <<~TIMEOUT_WARN
- Execution of pandoc timed out: #{e}.
-
- The document will not be replaced (probably due to syntax errors) because pandoc did not finish.
- If you're running PostgreSQL: You can try to cancel this run and retry the migration and with an increased timeout
- (OPENPROJECT_PANDOC_TIMEOUT_SECONDS, currently at #{pandoc.pandoc_timeout} seconds).
-
- If you're running MySQL: You need to restore your pre-upgrade backup first since it does not have transactional DDL.
-
- However, please note that pandoc sometimes trip up over specific textile parts that cause it to run indefinitely.
- In this case, you will have to manually fix the textile and increasing the timeout will achieve nothing.
- TIMEOUT_WARN
-
- non_convertible_textile_doc(textile)
- end
- rescue StandardError => e
- logger.error "Execution of pandoc failed: #{e}"
- raise e
- end
-
- def non_convertible_textile_doc(textile)
- <<~DOC
- # Warning: This document could not be converted, probably due to syntax errors.
- The below content is textile.
-
-
- <pre>
-
- #{textile}
-
- </pre>
- DOC
- end
-
- def models_to_convert
- {
- ::Announcement => [:text],
- ::AttributeHelpText => [:help_text],
- ::Comment => [:comments],
- ::WikiPage => [:text],
- ::WorkPackage => [:description],
- ::Message => [:content],
- ::News => [:description],
- OldForum => [:description],
- ::Project => [:description],
- ::Journal => [:notes],
- ::Journal::MessageJournal => [:content],
- ::Journal::WikiPageJournal => [:text],
- ::Journal::WorkPackageJournal => [:description],
- ::AttributeHelpText => [:help_text]
- }
- end
-
- def batches_of_objects_to_convert(klass, attributes)
- scopes = attributes.map { |attribute| klass.where.not(attribute => nil).where.not(attribute => '') }
-
- scope = scopes.shift
- scopes.each do |attribute_scope|
- scope = scope.or(attribute_scope)
- end
-
- # Iterate in batches to avoid plucking too much
- progress = ProgressBar.create(title: "Conversion", starting_at: 0, total: scope.count)
- scope.in_batches(of: 50) do |relation|
- yield relation, progress
- end
- progress.finish
- end
-
- def batch_update_statement(klass, attributes, values)
- table_name = klass.table_name
- sets = attributes.map { |a| "#{a} = new_values.#{a}" }.join(', ')
- new_values = values.map do |value_hash|
- text_values = value_hash.except(:id).map { |_, v| ActiveRecord::Base.connection.quote(v) }.join(', ')
- "(#{value_hash[:id]}, #{text_values})"
- end
-
- <<-SQL
- UPDATE #{table_name}
- SET
- #{sets}
- FROM (
- VALUES
- #{new_values.join(', ')}
- ) AS new_values (id, #{attributes.join(', ')})
- WHERE #{table_name}.id = new_values.id
- SQL
- end
-
- def concatenate_textile(textiles)
- textiles.join("\n\n#{DOCUMENT_BOUNDARY}\n\n")
- end
-
- def split_markdown(markdown)
- markdown.split("\n\n#{DOCUMENT_BOUNDARY}\n\n")
- end
-
- def cleanup_before_pandoc(textile)
- placeholder_for_inline_code_at(textile)
- drop_table_colspan_notation(textile)
- drop_table_alignment_notation(textile)
- move_class_from_code_to_pre(textile)
- remove_code_inside_pre(textile)
- convert_malformed_textile(textile)
- remove_empty_paragraphs(textile)
- replace_numbered_headings(textile)
- add_newline_to_avoid_lazy_blocks(textile)
- remove_spaces_before_table(textile)
- hard_breaks_within_multiline_tables(textile)
- wrap_blockquotes(textile)
- end
-
- def cleanup_after_pandoc(markdown)
- # Remove the \ pandoc puts before * and > at beginning of lines
- markdown.gsub!(/^((\\[*>])+)/) { $1.gsub("\\", "") }
-
- # Add a blank line before lists
- # But do not apply it to *emphasis* or **strong** at the start of a line (whitespace is important)
- markdown.gsub!(/^([^*].*)\n\* /, "\\1\n\n* ")
-
- # Remove the injected tag
- markdown.gsub!(' ' + TAG_FENCED_CODE_BLOCK, '')
-
- # Replace placeholder with real backtick
- markdown.gsub!(TAG_CODE, '`')
-
- # Un-escape Redmine link syntax to wiki pages
- markdown.gsub!('\[\[', '[[')
- markdown.gsub!('\]\]', ']]')
-
- # replace filtered out span with ins
- markdown.gsub!(/<span class="underline">(.+)<\/span>/, '<ins>\1</ins>')
-
- markdown.gsub!(/#{BLOCKQUOTE_START}\n(.+?)\n\n#{BLOCKQUOTE_END}/m) do
- $1.gsub(/(\n)([^\n]*)/, '\1> \2')
- end
-
- # Create markdown links from !image!:link syntax
- # ![alt](image])
- markdown.gsub! /(?<image>!\[[^\]]*\]\([^)]+\)):(?<link>https?:\S+)/,
- '[\k<image>](\k<link>)'
-
- # remove the escaping from links within parenthesis having a trailing slash
- # ([description](https://some/url/\))
- markdown.gsub! /\((?<pretext>.*?)\[(?<description>.*?)\]\((?<link>.*?)\\\)\)/,
- '(\k<pretext>[\k<description>](\k<link>))'
-
- convert_macro_syntax(markdown)
-
- markdown
- end
-
- # Convert old {{macroname(args)}} syntax to <macro class="macroname" data-arguments="">
- def convert_macro_syntax(markdown)
- old_macro_regex = /
- (!)? # escaping
- (
- \{\{ # opening tag
- ([\w\\_]+) # macro name
- (\(([^}]*)\))? # optional arguments
- \}\} # closing tag
- )
- /x
-
- markdown.gsub!(old_macro_regex) do
- esc = $1
- all = $2
- macro = $3.gsub('\_', '_')
- args = $5 || ''
- args_array = args.split(',').each(&:strip!)
- data = {}
-
- # Escaped macros should probably render as before?
- next all if esc.present?
-
- case macro
- when 'timeline'
- next content_tag :macro, I18n.t('macros.legacy_warning.timeline'), class: 'legacy-macro -macro-unavailable'
- when 'hello_world'
- next ''
- when 'include'
- macro = 'include_wiki_page'
- data[:page] = args
- when 'create_work_package_link'
- data[:type] = args_array[0] if args_array.length >= 1
- data[:classes] = args_array[1] if args_array.length >= 2
- else
- data[:arguments] = args if args.present?
- end
-
- content_tag :macro, '', class: macro, data:
- end
- end
-
- # OpenProject support @ inside inline code marked with @ (such as "@[email protected]@"), but not pandoc.
- # So we inject a placeholder that will be replaced later on with a real backtick.
- def placeholder_for_inline_code_at(textile)
- textile.gsub!(/@(\S+@\S+)@/, TAG_CODE + '\\1' + TAG_CODE)
- end
-
- # Drop table colspan/rowspan notation ("|\2." or "|/2.") because pandoc does not support it
- # See https://github.com/jgm/pandoc/issues/22
- def drop_table_colspan_notation(textile)
- textile.gsub!(/\|[\/\\]\d\. /, '| ')
- end
-
- # Drop table alignment notation ("|>." or "|<." or "|=.") because pandoc does not support it
- # See https://github.com/jgm/pandoc/issues/22
- def drop_table_alignment_notation(textile)
- textile.gsub!(/\|[<>=]\. /, '| ')
- end
-
- # Move the class from <code> to <pre> so pandoc can generate a code block with correct language
- def move_class_from_code_to_pre(textile)
- textile.gsub!(/(<pre)(><code)( class="[^"]*")(>)/, '\\1\\3\\2\\4')
- end
-
- # Remove the <code> directly inside <pre>, because pandoc would incorrectly preserve it
- def remove_code_inside_pre(textile)
- textile.gsub!(/(<pre[^>]*>)<code>/, '\\1')
- textile.gsub!(/<\/code>(<\/pre>)/, '\\1')
- end
-
- # Some malformed textile content make pandoc run extremely slow,
- # so we convert it to proper textile before hitting pandoc
- # see https://github.com/jgm/pandoc/issues/3020
- def convert_malformed_textile(textile)
- textile.gsub!(/- # (\d+)/, "* \\1")
- end
-
- # Remove empty paragraph blocks which trip up pandoc
- def remove_empty_paragraphs(textile)
- textile.gsub!(/\np(=|>)?\.[\s.]*\n/, '')
- end
-
- # Replace numbered headings as they are not supported in commonmark/gfm
- def replace_numbered_headings(textile)
- textile.gsub!(/h(\d+)#./, 'h\\1.')
- end
-
- # Add an additional newline before:
- # * every pre block prefixed by only one newline
- # as indented code blocks do not interrupt a paragraph and also do not have precedence
- # compared to a list which might also be indented.
- # * every table prefixed by only one newline (if the line before isn't a table already)
- # * every blockquote prefixed by one newline (if the line before isn't a blockquote)
- def add_newline_to_avoid_lazy_blocks(textile)
- textile.gsub!(/(\n[^>|]+)\r?\n(\s*)(<pre>|\||>)/, "\\1\n\n\\2\\3")
- end
-
- # Remove spaces before a table as that would lead to the table
- # not being identified
- def remove_spaces_before_table(textile)
- textile.gsub!(/^\s+(\|.+?\|)/, "\n\n\\1")
- end
-
- ##
- # Redmine introduced hard breaks to support multiline tables that are not official
- # textile. We detect tables with line breaks and replace them with <br/>
- # https://www.redmine.org/projects/redmine/repository/revisions/2824/diff/
- def hard_breaks_within_multiline_tables(textile)
- content_regexp = %r{
- (?<=\|) # Assert beginning table pipe lookbehind
- ([^|]{5,}) # Non-empty content
- (?=\|) # Assert ending table pipe lookahead
- }mx
-
- # Match all textile tables
- textile.gsub!(/^(\|.+?\|)$/m) do |table|
- table.gsub(content_regexp) { |table_content| table_content.gsub("\n", " <br/> ") }
- end
- end
-
- # Wrap all blockquote blocks into boundaries as `>` is not valid blockquote syntax and would thus be
- # escaped
- def wrap_blockquotes(textile)
- textile.gsub!(/((\n>[^\n]*)+)/m) do
- "\n#{BLOCKQUOTE_START}\n" + $1.gsub(/(\n)> *([^\n]*)/, '\1\2') + "\n\n#{BLOCKQUOTE_END}\n"
- end
- end
-
- class OldForum < ApplicationRecord
- self.table_name = 'boards'
- end
- end
- end
-end
diff --git a/modules/documents/lib/open_project/documents/engine.rb b/modules/documents/lib/open_project/documents/engine.rb
index 2c68809a421..05fb8956ffd 100644
--- a/modules/documents/lib/open_project/documents/engine.rb
+++ b/modules/documents/lib/open_project/documents/engine.rb
@@ -74,7 +74,5 @@ module OpenProject::Documents
# Add documents to allowed search params
additional_permitted_attributes search: %i(documents)
-
- patch_with_namespace :OpenProject, :TextFormatting, :Formats, :Markdown, :TextileConverter
end
end
diff --git a/modules/documents/lib/open_project/documents/patches/textile_converter_patch.rb b/modules/documents/lib/open_project/documents/patches/textile_converter_patch.rb
deleted file mode 100644
index 97bf04aa866..00000000000
--- a/modules/documents/lib/open_project/documents/patches/textile_converter_patch.rb
+++ /dev/null
@@ -1,42 +0,0 @@
-#-- copyright
-# OpenProject Documents Plugin
-#
-# Former OpenProject Core functionality extracted into a plugin.
-#
-# Copyright (C) 2009-2014 the OpenProject Foundation (OPF)
-#
-# This program is free software; you can redistribute it and/or
-# modify it under the terms of the GNU General Public License version 3.
-#
-# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
-# Copyright (C) 2006-2013 Jean-Philippe Lang
-# Copyright (C) 2010-2013 the ChiliProject Team
-#
-# 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.
-#
-# See COPYRIGHT and LICENSE files for more details.
-#+
-
-module OpenProject::Documents::Patches
- module TextileConverterPatch
- def models_to_convert
- super.merge(::Document => [:description])
- end
- end
-end
-
-OpenProject::TextFormatting::Formats::Markdown::TextileConverter.prepend(
- OpenProject::Documents::Patches::TextileConverterPatch
-)
diff --git a/modules/meeting/lib/open_project/meeting/engine.rb b/modules/meeting/lib/open_project/meeting/engine.rb
index 59680de3d48..07f3d07db63 100644
--- a/modules/meeting/lib/open_project/meeting/engine.rb
+++ b/modules/meeting/lib/open_project/meeting/engine.rb
@@ -108,8 +108,6 @@ module OpenProject::Meeting
patches [:Project]
patch_with_namespace :BasicData, :SettingSeeder
- patch_with_namespace :OpenProject, :TextFormatting, :Formats, :Markdown, :TextileConverter
-
add_api_endpoint 'API::V3::Root' do
mount ::API::V3::Meetings::MeetingContentsAPI
end
diff --git a/modules/meeting/lib/open_project/meeting/patches/textile_converter_patch.rb b/modules/meeting/lib/open_project/meeting/patches/textile_converter_patch.rb
deleted file mode 100644
index 2b68eac8a6a..00000000000
--- a/modules/meeting/lib/open_project/meeting/patches/textile_converter_patch.rb
+++ /dev/null
@@ -1,46 +0,0 @@
-#-- copyright
-# OpenProject is an open source project management software.
-# Copyright (C) 2012-2023 the OpenProject GmbH
-#
-# This program is free software; you can redistribute it and/or
-# modify it under the terms of the GNU General Public License version 3.
-#
-# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
-# Copyright (C) 2006-2013 Jean-Philippe Lang
-# Copyright (C) 2010-2013 the ChiliProject Team
-#
-# 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.
-#
-# See COPYRIGHT and LICENSE files for more details.
-#++
-
-module OpenProject::Meeting::Patches
- module TextileConverterPatch
- extend ActiveSupport::Concern
-
- included do
- prepend(Patch)
- end
-
- module Patch
- def models_to_convert
- super.merge(
- ::MeetingContent => [:text],
- ::Journal::MeetingContentJournal => [:text]
- )
- end
- end
- end
-end
diff --git a/modules/overviews/lib/overviews/engine.rb b/modules/overviews/lib/overviews/engine.rb
index f8107a80f5b..8c4caf4778b 100644
--- a/modules/overviews/lib/overviews/engine.rb
+++ b/modules/overviews/lib/overviews/engine.rb
@@ -30,8 +30,6 @@ module Overviews
end
end
- patch_with_namespace :OpenProject, :TextFormatting, :Formats, :Markdown, :TextileConverter
-
initializer 'overviews.conversion' do
require Rails.root.join('config/constants/ar_to_api_conversions')
diff --git a/modules/overviews/lib/overviews/patches/textile_converter_patch.rb b/modules/overviews/lib/overviews/patches/textile_converter_patch.rb
deleted file mode 100644
index a17183a8a9e..00000000000
--- a/modules/overviews/lib/overviews/patches/textile_converter_patch.rb
+++ /dev/null
@@ -1,43 +0,0 @@
-# As the successor to the MyProjectPage Plugin and possibly inheriting the data from it,
-# we Overview needs to convert textile in custom_text widgets. The converter can be executed after
-# the migration.
-
-module Overviews::Patches
- module TextileConverterPatch
- extend ActiveSupport::Concern
-
- included do
- prepend(Patch)
- end
-
- module Patch
- def convert_custom_text_widgets
- # If the table does not exist yet, there is nothing to convert
- return unless Grids::Overview.table_exists?
-
- print Grids::Overview.name
-
- text_widgets_to_convert
- .in_batches(of: 200) do |widget|
- widget.options['text'] = convert_textile_to_markdown(widget.options['text']) if widget.options['text']
- widget.save
-
- print ' .'
- end
-
- print 'done'
- end
-
- def text_widgets_to_convert
- Grids::Widget
- .includes(:grid)
- .where(grids: { type: 'Grids::Overview' })
- .where(identifier: 'custom_text')
- end
-
- def converters
- super + [method(:convert_custom_text_widgets)]
- end
- end
- end
-end
diff --git a/script/ci/setup.sh b/script/ci/setup.sh
index fab0418f768..e3c299b222a 100644
--- a/script/ci/setup.sh
+++ b/script/ci/setup.sh
@@ -56,12 +56,6 @@ if [ $1 = 'npm' ]; then
echo "No asset compilation required"
fi
-if [ $1 = 'units' ]; then
- # Install pandoc for testing textile migration
- run "sudo apt-get update -qq"
- run "sudo apt-get install -qq pandoc"
-fi
-
if [ ! -f "public/assets/frontend_assets.manifest.json" ]; then
if [ -z "${RECOMPILE_ON_TRAVIS_CACHE_ERROR}" ]; then
echo "ERROR: asset manifest was not properly cached. exiting"
diff --git a/spec/lib/open_project/text_formatting/markdown/pandoc_wrapper_spec.rb b/spec/lib/open_project/text_formatting/markdown/pandoc_wrapper_spec.rb
deleted file mode 100644
index d5d40ccffb5..00000000000
--- a/spec/lib/open_project/text_formatting/markdown/pandoc_wrapper_spec.rb
+++ /dev/null
@@ -1,83 +0,0 @@
-#-- copyright
-# OpenProject is an open source project management software.
-# Copyright (C) 2012-2023 the OpenProject GmbH
-#
-# This program is free software; you can redistribute it and/or
-# modify it under the terms of the GNU General Public License version 3.
-#
-# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
-# Copyright (C) 2006-2013 Jean-Philippe Lang
-# Copyright (C) 2010-2013 the ChiliProject Team
-#
-# 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.
-#
-# See COPYRIGHT and LICENSE files for more details.
-#++
-
-require 'spec_helper'
-
-RSpec.describe OpenProject::TextFormatting::Formats::Markdown::PandocWrapper do
- let(:subject) { described_class.new }
-
- before do
- allow(subject).to receive(:read_usage_string).and_return(usage_string)
- end
-
- describe 'wrap mode' do
- context 'when wrap=preserve exists' do
- let(:usage_string) do
- <<~EOS
- --list-output-formats#{' '}
- --list-highlight-languages#{' '}
- --list-highlight-styles#{' '}
- --wrap=auto|none|preserve
- -v --version#{' '}
- -h --help
- EOS
- end
-
- it do
- expect(subject.wrap_mode).to eq('--wrap=preserve')
- end
- end
-
- context 'when only no-wrap exists' do
- let(:usage_string) do
- <<~EOS
- --list-output-formats#{' '}
- --list-highlight-languages#{' '}
- --list-highlight-styles#{' '}
- --no-wrap
- -v --version#{' '}
- -h --help
- EOS
- end
-
- it do
- expect(subject.wrap_mode).to eq('--no-wrap')
- end
- end
-
- context 'when neither exists' do
- let(:usage_string) { 'wat?' }
-
- it do
- expect do
- subject.wrap_mode
- end.to raise_error 'Your pandoc version has neither --no-wrap nor --wrap=preserve. Please install a recent version of pandoc.'
- end
- end
- end
-end
diff --git a/vendor/.gitignore b/vendor/.gitignore
deleted file mode 100644
index 9b3f842a9d7..00000000000
--- a/vendor/.gitignore
+++ /dev/null
@@ -1 +0,0 @@
-pandoc/