From 35594b23131311be8525a4a4fcac0f3ed633a157 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oliver=20G=C3=BCnther?= Date: Wed, 4 Jul 2018 08:42:59 +0200 Subject: [PATCH] [27951][27952] Convert macro syntax and show warning for legacy macro --- .../stylesheets/content/editor/_ckeditor.sass | 11 +---- .../stylesheets/content/editor/_macros.sass | 17 ++++++++ config/locales/en.yml | 2 + .../formatters/markdown/textile_converter.rb | 43 +++++++++++++++++-- 4 files changed, 61 insertions(+), 12 deletions(-) create mode 100644 app/assets/stylesheets/content/editor/_macros.sass diff --git a/app/assets/stylesheets/content/editor/_ckeditor.sass b/app/assets/stylesheets/content/editor/_ckeditor.sass index 89f33589a3..f2106622fb 100644 --- a/app/assets/stylesheets/content/editor/_ckeditor.sass +++ b/app/assets/stylesheets/content/editor/_ckeditor.sass @@ -1,3 +1,5 @@ +@import './macros' + // Wrapper for inline text editor .op-ckeditor-element min-height: 50px @@ -17,12 +19,3 @@ // Min height for the editable section .ck-editor__editable min-height: 20vh - - .ck-widget.macro - border: 2px dashed #ccc - min-height: 50px - display: flex - justify-content: center - align-items: center - color: #575757 - background: #f8f8f8 diff --git a/app/assets/stylesheets/content/editor/_macros.sass b/app/assets/stylesheets/content/editor/_macros.sass new file mode 100644 index 0000000000..83523e04e2 --- /dev/null +++ b/app/assets/stylesheets/content/editor/_macros.sass @@ -0,0 +1,17 @@ +// Legacy macro rendering +macro.legacy-macro + background: $nm-color-warning-background + border: 2px dashed $nm-color-warning-border + padding: 10px 5px + +// Macro rendering in CKEditor +.op-ckeditor--wrapper + + .ck-widget.macro + border: 2px dashed #ccc + min-height: 50px + display: flex + justify-content: center + align-items: center + color: #575757 + background: #f8f8f8 diff --git a/config/locales/en.yml b/config/locales/en.yml index 5457655502..4726f00f2f 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -1619,6 +1619,8 @@ en: macro_execution_error: "Error executing the macro %{macro_name}" macro_unavailable: "Macro %{macro_name} cannot be displayed." macros: + legacy_warning: + timeline: 'This legacy timeline macro has been removed and is no longer available. You can replace the functionality with an embedded table macro.' create_work_package_link: errors: no_project_context: 'Calling create_work_package_link macro from outside project context.' diff --git a/lib/open_project/text_formatting/formatters/markdown/textile_converter.rb b/lib/open_project/text_formatting/formatters/markdown/textile_converter.rb index 38b22ed3aa..d196ba1485 100644 --- a/lib/open_project/text_formatting/formatters/markdown/textile_converter.rb +++ b/lib/open_project/text_formatting/formatters/markdown/textile_converter.rb @@ -57,6 +57,8 @@ require 'open3' module OpenProject::TextFormatting::Formatters 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 @@ -93,7 +95,7 @@ module OpenProject::TextFormatting::Formatters print '.' end - puts 'done' + puts ' done' end ## @@ -112,7 +114,7 @@ module OpenProject::TextFormatting::Formatters ActiveRecord::Base.connection.execute(batch_update_statement(klass, attributes, new_values)) end - puts 'done' + puts ' done' end end @@ -126,7 +128,7 @@ module OpenProject::TextFormatting::Formatters end end - puts 'done' + puts ' done' end # Iterate in batches to avoid plucking too much @@ -322,9 +324,44 @@ module OpenProject::TextFormatting::Formatters $1.gsub(/([\n])([^\n]*)/, '\1> \2') end + convert_macro_syntax(markdown) + markdown end + # Convert old {{macroname(args)}} syntax to + 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 || '' + + # Escaped macros should probably render as before? + return all if esc.present? + + case macro + when 'timeline' + content_tag :macro, I18n.t('macros.legacy_warning.timeline'), class: 'legacy-macro -macro-unavailable' + when 'hello_world' + '' + else + data = args.present? ? { arguments: args } : {} + content_tag :macro, '', class: macro, data: data + end + end + end + # OpenProject support @ inside inline code marked with @ (such as "@git@github.com@"), 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)