diff --git a/app/assets/stylesheets/content/editor/_macros.sass b/app/assets/stylesheets/content/editor/_macros.sass index 05449eddc1..4bf0fa7b05 100644 --- a/app/assets/stylesheets/content/editor/_macros.sass +++ b/app/assets/stylesheets/content/editor/_macros.sass @@ -4,7 +4,8 @@ macro.legacy-macro border: 2px dashed $nm-color-warning-border padding: 10px 5px -.ck-widget.macro +.ck-widget.macro, +macro.macro-placeholder border: 2px dashed #ccc min-height: 50px display: flex diff --git a/app/controllers/wiki_controller.rb b/app/controllers/wiki_controller.rb index fb04ec12d5..a7182e908c 100644 --- a/app/controllers/wiki_controller.rb +++ b/app/controllers/wiki_controller.rb @@ -285,7 +285,10 @@ class WikiController < ApplicationController def diff if (@diff = @page.diff(params[:version], params[:version_from])) - @html_diff = HTMLDiff::DiffBuilder.new(@diff.content_from.data.text, @diff.content_to.data.text).build + @html_diff = HTMLDiff::DiffBuilder.new( + helpers.format_text(@diff.content_from.data.text, disable_macro_expansion: true), + helpers.format_text(@diff.content_to.data.text, disable_macro_expansion: true) + ).build else render_404 end diff --git a/config/locales/en.yml b/config/locales/en.yml index 93b7c76366..2f7d62d83c 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -1613,6 +1613,7 @@ en: macro_execution_error: "Error executing the macro %{macro_name}" macro_unavailable: "Macro %{macro_name} cannot be displayed." macros: + placeholder: '[Placeholder] Macro %{macro_name}' errors: missing_or_invalid_parameter: 'Missing or invalid macro parameter.' legacy_warning: diff --git a/lib/open_project/text_formatting/filters/macro_filter.rb b/lib/open_project/text_formatting/filters/macro_filter.rb index 5bbf156a84..12543fd232 100644 --- a/lib/open_project/text_formatting/filters/macro_filter.rb +++ b/lib/open_project/text_formatting/filters/macro_filter.rb @@ -44,6 +44,12 @@ module OpenProject::TextFormatting registered.each do |macro_class| next unless Array(macro['class']).include? macro_class.identifier + # If requested to skip macro expansion, do that + if context[:disable_macro_expansion] + macro.replace macro_placeholder(macro_class) + break + end + begin macro_class.apply(macro, result: result, context: context) rescue => e @@ -65,6 +71,14 @@ module OpenProject::TextFormatting class: 'macro-unavailable', data: { macro_name: macro_class.identifier } end + + + def macro_placeholder(macro_class) + ApplicationController.helpers.content_tag :macro, + I18n.t('macros.placeholder', macro_name: macro_class.identifier), + class: 'macro-placeholder', + data: { macro_name: macro_class.identifier } + end end end end @@ -73,5 +87,6 @@ OpenProject::TextFormatting::Filters::MacroFilter.register( OpenProject::TextFormatting::Filters::Macros::Toc, OpenProject::TextFormatting::Filters::Macros::CreateWorkPackageLink, OpenProject::TextFormatting::Filters::Macros::IncludeWikiPage, + OpenProject::TextFormatting::Filters::Macros::EmbeddedTable, OpenProject::TextFormatting::Filters::Macros::ChildPages ) diff --git a/lib/open_project/text_formatting/filters/macros/embedded_table.rb b/lib/open_project/text_formatting/filters/macros/embedded_table.rb new file mode 100644 index 0000000000..1c79e51632 --- /dev/null +++ b/lib/open_project/text_formatting/filters/macros/embedded_table.rb @@ -0,0 +1,49 @@ +#-- encoding: UTF-8 + +#-- copyright +# OpenProject is a project management system. +# Copyright (C) 2012-2017 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-2017 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 doc/COPYRIGHT.rdoc for more details. +#++ + +module OpenProject::TextFormatting::Filters::Macros + module EmbeddedTable + HTML_CLASS = 'embedded-table'.freeze + + module_function + + def identifier + HTML_CLASS + end + + def apply(*_args) + # Nothing to do + end + + def is?(macro) + macro['class'].include?(HTML_CLASS) + end + end +end