[28179] Disable macro expansion in wiki diff

https://community.openproject.com/wp/28179
pull/6512/head
Oliver Günther 6 years ago
parent d8582f9df7
commit 47628b71d6
No known key found for this signature in database
GPG Key ID: A3A8BDAD7C0C552C
  1. 3
      app/assets/stylesheets/content/editor/_macros.sass
  2. 5
      app/controllers/wiki_controller.rb
  3. 1
      config/locales/en.yml
  4. 15
      lib/open_project/text_formatting/filters/macro_filter.rb
  5. 49
      lib/open_project/text_formatting/filters/macros/embedded_table.rb

@ -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

@ -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

@ -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:

@ -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
)

@ -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
Loading…
Cancel
Save