Merge pull request #6408 from opf/feature/convert-macros

[27951][27952] Convert macro syntax and show warning for legacy macro

[ci skip]
pull/6410/head
Oliver Günther 6 years ago committed by GitHub
commit 6513011af8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 11
      app/assets/stylesheets/content/editor/_ckeditor.sass
  2. 17
      app/assets/stylesheets/content/editor/_macros.sass
  3. 2
      config/locales/en.yml
  4. 43
      lib/open_project/text_formatting/formatters/markdown/textile_converter.rb

@ -1,3 +1,5 @@
@import './macros'
// Wrapper for inline text editor // Wrapper for inline text editor
.op-ckeditor-element .op-ckeditor-element
min-height: 50px min-height: 50px
@ -17,12 +19,3 @@
// Min height for the editable section // Min height for the editable section
.ck-editor__editable .ck-editor__editable
min-height: 20vh 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

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

@ -1619,6 +1619,8 @@ en:
macro_execution_error: "Error executing the macro %{macro_name}" macro_execution_error: "Error executing the macro %{macro_name}"
macro_unavailable: "Macro %{macro_name} cannot be displayed." macro_unavailable: "Macro %{macro_name} cannot be displayed."
macros: 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: create_work_package_link:
errors: errors:
no_project_context: 'Calling create_work_package_link macro from outside project context.' no_project_context: 'Calling create_work_package_link macro from outside project context.'

@ -57,6 +57,8 @@ require 'open3'
module OpenProject::TextFormatting::Formatters module OpenProject::TextFormatting::Formatters
module Markdown module Markdown
class TextileConverter class TextileConverter
include ActionView::Helpers::TagHelper
TAG_CODE = 'pandoc-unescaped-single-backtick'.freeze TAG_CODE = 'pandoc-unescaped-single-backtick'.freeze
TAG_FENCED_CODE_BLOCK = 'force-pandoc-to-ouput-fenced-code-block'.freeze TAG_FENCED_CODE_BLOCK = 'force-pandoc-to-ouput-fenced-code-block'.freeze
DOCUMENT_BOUNDARY = "TextileConverterDocumentBoundary09339cab-f4f4-4739-85b0-d02ba1f342e6".freeze DOCUMENT_BOUNDARY = "TextileConverterDocumentBoundary09339cab-f4f4-4739-85b0-d02ba1f342e6".freeze
@ -93,7 +95,7 @@ module OpenProject::TextFormatting::Formatters
print '.' print '.'
end end
puts 'done' puts ' done'
end end
## ##
@ -112,7 +114,7 @@ module OpenProject::TextFormatting::Formatters
ActiveRecord::Base.connection.execute(batch_update_statement(klass, attributes, new_values)) ActiveRecord::Base.connection.execute(batch_update_statement(klass, attributes, new_values))
end end
puts 'done' puts ' done'
end end
end end
@ -126,7 +128,7 @@ module OpenProject::TextFormatting::Formatters
end end
end end
puts 'done' puts ' done'
end end
# Iterate in batches to avoid plucking too much # Iterate in batches to avoid plucking too much
@ -322,9 +324,44 @@ module OpenProject::TextFormatting::Formatters
$1.gsub(/([\n])([^\n]*)/, '\1> \2') $1.gsub(/([\n])([^\n]*)/, '\1> \2')
end end
convert_macro_syntax(markdown)
markdown markdown
end 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 || ''
# 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. # 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. # So we inject a placeholder that will be replaced later on with a real backtick.
def placeholder_for_inline_code_at(textile) def placeholder_for_inline_code_at(textile)

Loading…
Cancel
Save