Macro help - edit parameter in WYSIWYG causes line breaks to disappear

Hi,
i am trying to create a macro that allows me to edit the value of my macro parameters directly in the WYSIWYG editor (not in the macro pop up window).
So far i achieving it by adding a “<div>” tag with specific values while in edit mode around the parameter. I am able to edit my macro parameters directly in the WYSIWYG editor, but if i try to edit them again all line breaks are gone.
My goal is to be able to edit the content of the show/hide macro directly inside the WYSIWYG editor (not in the macro pop up window). I only render the show/hide macro when the context action is view or preview. As i mentioned everything works fine except that after a re-edit all line breaks are gone.
Any ideas what i could do?

{{velocity}}
#set ($text = $xcontext.macro.params.CommandBlockText )

## Add a wrapping div as a sample of the action of this macro
#set($edittext = '(% data-xwiki-non-generated-content="java.util.List&lt;org.xwiki.rendering.block.Block&gt;" data-xwiki-parameter-name="CommandBlockText" data-xwiki-wikimacrocontent="true" class="xwiki-metadata-container cke_widget_editable" data-cke-widget-editable="CommandBlockText" data-cke-enter-mode="1" data-cke-display-name="CommandBlockText" contenteditable="true" %)((('+ $text +')))')
#set($wikimacro.result = $services.rendering.parse($edittext, $xwiki.getCurrentContentSyntaxId()).getChildren())

{{/velocity}}

First edit:
Bildschirmfoto%20vom%202019-08-09%2016-11-25
Rendered view:
Bildschirmfoto%20vom%202019-08-09%2016-12-04
Second time in edit mode:
Bildschirmfoto%20vom%202019-08-09%2016-11-03

Use java.util.List&lt; org.xwiki.rendering.block.Block &gt; (notice the whitespaces) or upgrade the CKEditor Integration extension to version 1.37+

Thank you for your help!
I upgraded the CKEditor Integration extension to version 1.37 and integrated the suggest code into my macro code. Unfortunately the outcome is still the same and all line breaks will be removed, if I enter the edit mode a second time, like I posted before. Since it is working on the box macro I will try to implement a Java version of my macro with the given maven archetype for a macro, unless there is another solution.
Nevertheless, thank you for your help and time!

Hi @ttsp, interesting use case for inline editing :slight_smile:
Couldn’t you use in your case the new macro we introduced to allow inline editing of parameters?

{{wikimacroparameter name="CommandBlockText" /}}

Note that this macro is not made to process the retrieved value of the parameter in a script, but just to render and allow editing of the param.

Thank you for the advise.
I already used new new macro

{{wikimacroparameter name="CommandBlockText" /}}

in my macro groovy script part. something like:

{{groovy}}
...
println "{{wikimacroparameter name='CommandBlockText' /}}"
....
{{/groovy}}

Unfortunately same result as I mentioned.
I will try to keep it out of a script. Maybe i will get a solution for my problem.
Thanks for your help!

Might be a bug on our side then, those features are pretty new. Do you have a simple way to reproduce the problem? A link to your script maybe?

Sure,
i just created a macro class with the following content and a macroparameter class in a subwiki of a multiwiki enviroment:

macro class
Supports inline mode: no (tested yes same result)
Macro visibility: current wiki
Macro content availability: optional
Macro content type: wiki (tested unkown same result)

macro parameter:
Parameter mandatory: no
Parameter type: java.util.List

{{groovy}}
println "{{box cssClass='mycontentbox'}}"
println "{{wikimacroparameter name='CommandBlockText' /}}"
println "{{/box}}"
{{/groovy}}


Steps to reproduce after the macro classes are created:

  1. Go to a site of your choice and edit a section of your choice
  2. insert the macro
  3. add some content which includes lines breaks as macro parameter like:
here
is my
Text
  1. hit “preview”
  2. hit “edit”
    Result line breaks are gone
hereis myText

Any type that is not listed on https://github.com/xwiki-contrib/application-ckeditor/blob/master/webjar/src/main/resources/config.js#L114 is handled as “plain text”.

Thx for the help.
So far i found a solution, that is working but still has some minor issues.
I switched from groovy to velocity and changed:

(% data-xwiki-non-generated-content="java.util.List&lt;org.xwiki.rendering.block.Block&gt;" data-xwiki-parameter-name="CommandBlockText" data-xwiki-wikimacrocontent="true" class="xwiki-metadata-container cke_widget_editable" data-cke-widget-editable="CommandBlockText" data-cke-enter-mode="1" data-cke-display-name="CommandBlockText" contenteditable="true" %)

to

(% data-xwiki-non-generated-content="java.util.List<org.xwiki.rendering.block.Block>" data-xwiki-parameter-name="CommandBlockText" data-xwiki-wikimacrocontent="true" class="xwiki-metadata-container cke_widget_editable" data-cke-widget-editable="CommandBlockText" data-cke-enter-mode="2" data-cke-filter="84" data-cke-display-name="CommandBlockText" contenteditable="true" %)
&lt; to <  ...

All parameter types now have the default type (macro still works if i change them to java.util.List)

Issues:
Editing a parameter in the WYSIWYG editor

  1. Adding a info box via the macro selection in the WYSIWYG editor needs some tweaking but is mostly working. Sometimes the user needs to add extra line (especially in tables) after the info box
  2. Adding a info box via the style selection in the WYSIWYG editor is broken and will result in:
    2.1 rendering only the content of the info box not the box itself
    2.2 removing the box with its content

Here my macro code:

{{velocity}}
#set ($contents = $xcontext.macro.content )
#set ($codelanguage  = $xcontext.macro.params.codeLanguage  )
#set ($tabellenLink  = $xcontext.macro.params.TabellenLink  )
#set ($text = $xcontext.macro.params.CommandBlockText )
#set ($commandtable = '
(% class="configtable" %)
|=Property Name|=Beschreibung|=Werte|=Version
||||')

#if($tabellenLink == "Kommandotabelle")
#set ($tabellenLink = $commandtable)
#end

#if (($xcontext.action == 'get') || ($xcontext.action == 'edit'))
#set ($editresult = '
(% data-xwiki-non-generated-content="java.util.List<org.xwiki.rendering.block.Block>" data-xwiki-parameter-name="CommandBlockText" data-xwiki-wikimacrocontent="true" class="xwiki-metadata-container cke_widget_editable" data-cke-widget-editable="CommandBlockText" data-cke-enter-mode="2" data-cke-filter="84" data-cke-display-name="CommandBlockText" contenteditable="true" %)((('+ $text +')))
(% data-xwiki-non-generated-content="java.util.List<org.xwiki.rendering.block.Block>" data-xwiki-parameter-name="TabellenLink" data-xwiki-wikimacrocontent="true" class="xwiki-metadata-container cke_widget_editable" data-cke-widget-editable="TabellenLink" data-cke-enter-mode="2" data-cke-filter="84" data-cke-display-name="TabellenLink" contenteditable="true" %)((('+ $tabellenLink +')))
{{code language="'+ $codelanguage+ '" }}
'+ $contents +'
{{/code}}')
#set($wikimacro.result = $services.rendering.parse($editresult, $xwiki.getCurrentContentSyntaxId()).getChildren())
#end

#if (($xcontext.action == 'view') || ($xcontext.action == 'preview'))
#set ($viewresult = '{{box cssClass="mycontentbox"}}'+
'(% data-xwiki-non-generated-content="java.util.List<org.xwiki.rendering.block.Block>" data-xwiki-parameter-name="CommandBlockText" data-xwiki-wikimacrocontent="true" class="xwiki-metadata-container cke_widget_editable" data-cke-widget-editable="CommandBlockText" data-cke-enter-mode="2" data-cke-filter="84" data-cke-display-name="CommandBlockText" contenteditable="true" %)((('+ $text +')))'+'
{{showhide showmessage="⚪ Tabelle der Kommandoeigenschaften anzeigen" hidemessage="⚫ Tabelle der Kommandoeigenschaften verbergen" effect="blind" effectduration="0.1" visible="true"}}'+
'(% data-xwiki-non-generated-content="java.util.List<org.xwiki.rendering.block.Block>" data-xwiki-parameter-name="TabellenLink" data-xwiki-wikimacrocontent="true" class="xwiki-metadata-container cke_widget_editable" data-cke-widget-editable="TabellenLink" data-cke-enter-mode="2" data-cke-filter="84" data-cke-display-name="TabellenLink" contenteditable="true" %)((('+ $tabellenLink +')))'+'
{{/showhide}}

{{showhide showmessage="⚪ Kommandodatei anzeigen" hidemessage="⚫ Kommandodatei verbergen" effect="blind" effectduration="0.1" visible="true"}}
{{code language="'+$codelanguage+'" }}'+
 $contents+'
{{/code}}
{{/showhide}}
{{/box}}')
#set($wikimacro.result = $services.rendering.parse($viewresult, $xwiki.getCurrentContentSyntaxId()).getChildren())
#end

#if ($xcontext.action == 'export' && $request.format == 'pdf')
#set ($pdfresult = '{{box cssClass="mycontentbox"}}'
+ $text +''+
$tabellenLink +'

{{code language="'+$codelanguage+'" }}'+
 $contents+'
{{/code}}

{{/box}}')
#set($wikimacro.result = $services.rendering.parse($pdfresult, $xwiki.getCurrentContentSyntaxId()).getChildren())
#end
{{/velocity}}