[xwiki-users] Defining a macro for the confluence syntax
Hello XWiki experts, I'm porting confluence-syntax-pages from a confluence to my shiny new xwiki. I've made a little tool to grasp the attachments (by hand) and am copying the page content. These pages were using two macros that I am try to reprogramme but am failing thus far. I succeeded creating the macro with the easy tutorial here http://platform.xwiki.org/xwiki/bin/view/DevGuide/WikiMacroTutorial, including content or parameters references in the XWiki 2.1 syntax but in the confluence syntax I am failing: - how can I specify macro parameters there? - confluence macros do not have open and close tags. Does it mean it cannot have content? If the macro requires content, an error is displayed constantly that the content is missing. thanks Paul
Hi Paul, On 17 Sep 2015 at 09:36:30, Paul Libbrecht (paul@hoplahup.net(mailto:paul@hoplahup.net)) wrote:
Hello XWiki experts,
I'm porting confluence-syntax-pages from a confluence to my shiny new xwiki. I've made a little tool to grasp the attachments (by hand) and am copying the page content. These pages were using two macros that I am try to reprogramme but am failing thus far.
BTW do you know that we have a Confluence importer? :) http://extensions.xwiki.org/xwiki/bin/view/Extension/Filter+Confluence+XML+m...
I succeeded creating the macro with the easy tutorial here http://platform.xwiki.org/xwiki/bin/view/DevGuide/WikiMacroTutorial, including content or parameters references in the XWiki 2.1 syntax but in the confluence syntax I am failing: - how can I specify macro parameters there? - confluence macros do not have open and close tags. Does it mean it cannot have content? If the macro requires content, an error is displayed constantly that the content is missing.
If you’re interested in the Confluence grammar: https://github.com/xwiki/xwiki-rendering/blob/ae956128c40efd0445e15d531d2bf0... So you can have params for example: {color:red}…{color} From the grammar file it seems only some macros may be recognized… I don’t know why the grammar doesn’t have a generic way to recognize a macro, this should probably be improved. Thanks -Vincent
thanks
Paul
On 17 Sep 2015 at 09:53:31, vincent@massol.net (vincent@massol.net(mailto:vincent@massol.net)) wrote:
Hi Paul,
On 17 Sep 2015 at 09:36:30, Paul Libbrecht (paul@hoplahup.net(mailto:paul@hoplahup.net)) wrote:
Hello XWiki experts,
I'm porting confluence-syntax-pages from a confluence to my shiny new xwiki. I've made a little tool to grasp the attachments (by hand) and am copying the page content. These pages were using two macros that I am try to reprogramme but am failing thus far.
BTW do you know that we have a Confluence importer? :)
http://extensions.xwiki.org/xwiki/bin/view/Extension/Filter+Confluence+XML+m...
I succeeded creating the macro with the easy tutorial here http://platform.xwiki.org/xwiki/bin/view/DevGuide/WikiMacroTutorial, including content or parameters references in the XWiki 2.1 syntax but in the confluence syntax I am failing: - how can I specify macro parameters there? - confluence macros do not have open and close tags. Does it mean it cannot have content? If the macro requires content, an error is displayed constantly that the content is missing.
If you’re interested in the Confluence grammar: https://github.com/xwiki/xwiki-rendering/blob/ae956128c40efd0445e15d531d2bf0...
So you can have params for example: {color:red}…{color}
From the grammar file it seems only some macros may be recognized… I don’t know why the grammar doesn’t have a generic way to recognize a macro, this should probably be improved.
Forget that, I misread. The grammar says: | <#MACRO_PARAMS: ( <ESCAPED> | ~["}"] )* > | <#MACRO: "{" <CHAR> <MACRO_PARAMS> "}” > | <#MACRO_CONTENT: ( <ESCAPED> | <CHAR> | <SPACE> |<NEW_LINE> | <SPECIAL_SYMBOL> ) > | <#MACRO_BLOCK: "{" ( "color" // TODO: {color:xx} paragraph {color} … ) <MACRO_PARAMS> "}" > so it should work fine. I also see in ConfluenceWikiScanner.splitMacroParams() the code to split the parameters. I haven’t tried it for real though :) Now I’d recommend that once you have a page in Confluence syntax inside XWiki, you convert it to XWiki Syntax 2.1 and then you won’t have any problem in using any wiki macro or the WYSIWYG editor and all features of XWiki in general. Note: It’s still interesting to me to make macros work well in the confluence syntax so if you want to continue on that path I’m happy to help as I can. Thanks -Vincent
Thanks -Vincent
thanks
Paul
Hello Vincent,
> so it should work fine. I also see
> in ConfluenceWikiScanner.splitMacroParams() the code to split the
> parameters.
Nope, it failed.
What worked is to read a parameter or make it an {html} macro though:
- {jsmath:f=\\frac\{x\}\{x+3\}}
- {html}\( \frac{x+3}{x} \){html}
The first, however, is a plague to use because of th eneed to escape all
curly brackets.
> Note: It's still interesting to me to make macros work well in the
> confluence syntax so if you want to continue on that path I'm happy to
> help as I can.
is it useful to document it somewhere? where?
That's easy enough to keep it in Confluence for now.
> Now I'd recommend that once you have a page in Confluence syntax
> inside XWiki, you convert it to XWiki Syntax 2.1 and then you won't
> have any problem in using any wiki macro or the WYSIWYG editor and all
> features of XWiki in general.
Good point. I'll keep that in mind as the next step.
> > BTW do you know that we have a Confluence importer? :)
I know it but the confluence I import from is a version 3 and
apparently, confluence version 4 and 5 cannot import xml exports of
version 3. This importer seems to be focussed on version 5 which is the
latest and it's good this way.
I wonder if such importers should not stay at the level of scripting
code which others hack.
My little solution works just for me and that's fine this way... and
probably improters will be this way for a long time.
Paul
Hi Paul, On 18 Sep 2015 at 18:30:01, Paul Libbrecht (paul@hoplahup.net(mailto:paul@hoplahup.net)) wrote:
Hello Vincent,
so it should work fine. I also see in ConfluenceWikiScanner.splitMacroParams() the code to split the parameters. Nope, it failed.
What failed? I was just saying that our Confluence parser should support macros. I’ve just tried writing a page in Confluence syntax using an existing XWiki macro and it worked: {html}<strong>hello</strong>{html} This worked too: {documentTree} This worked too (showing we can pass one parameter): {documentTree:checkboxes=true} This worked too (showing you can pass more than 1 parameter): {documentTree:checkboxes=true|root=space:xwiki:Blog}
What worked is to read a parameter or make it an {html} macro though: - {jsmath:f=\\frac\{x\}\{x+3\}} - {html}\( \frac{x+3}{x} \){html} The first, however, is a plague to use because of th eneed to escape all curly brackets.
Note: It’s still interesting to me to make macros work well in the confluence syntax so if you want to continue on that path I’m happy to help as I can. is it useful to document it somewhere? where?
What would you wish to document? The Confluence syntax? If so I think we should point to some reference page from the Atlassian site instead (putting a link here: http://rendering.xwiki.org/xwiki/bin/view/Main/WebHome#HSupportedSyntaxes).
That's easy enough to keep it in Confluence for now.
Now I’d recommend that once you have a page in Confluence syntax inside XWiki, you convert it to XWiki Syntax 2.1 and then you won’t have any problem in using any wiki macro or the WYSIWYG editor and all features of XWiki in general. Good point. I'll keep that in mind as the next step.
BTW do you know that we have a Confluence importer? :) I know it but the confluence I import from is a version 3 and apparently, confluence version 4 and 5 cannot import xml exports of version 3. This importer seems to be focussed on version 5 which is the latest and it's good this way.
Ok, didn’t know about your version and the one our importer supports.
I wonder if such importers should not stay at the level of scripting code which others hack.
Are you referring to our Confluence importer? Do you mean not writing our official importer in java but instead in script in wiki pages?
My little solution works just for me and that's fine this way... and probably improters will be this way for a long time.
Thanks -Vincent
Paul
Hello Vincent,
What failed? Reading the content. I was just saying that our Confluence parser should support macros. I’ve just tried writing a page in Confluence syntax using an existing XWiki macro and it worked:
{html}<strong>hello</strong>{html} I can't explain why this one works but I presume there's a switch internally to it that automatically converts the html macro into a closing html macro (and indeed, it's nonsense to nest html). This worked too:
{documentTree} This worked too (showing we can pass one parameter): {documentTree:checkboxes=true} Yes, parameters reading (single and multiple) worked fine (but they need escaping).
I tried a tick more formally to see if I could make a macro with content and failed. Here's how. Page: {testmacro} this is the content {testmacro} Macro: (Tools.TestMacro, object XWiki.WikiMacroClass) id: testmacro inline: no (I tried yes too, with inlined macro in the page) visibility: global macro content type: optional macro code: testMacroStart{{velocity}}$!xcontext.macro.content{{/velocity}}testMacroEnd The resulting page gives: testMacroStarttestMacroEnd this is the content testMacroStarttestMacroEnd I tried to adjust the content type to mandatory but this bragged... having no content! If macro content was thinkable, then there should be somewhere in the grammar a different mark for start and end macro or? I don't see the latter. Since, according to https://developer.atlassian.com/confdev/tutorials/macro-tutorials-for-conflu..., "there are three available body types for macros: PLAIN_TEXT, RICH_TEXT, and NONE. ", I suppose the only solution is to make the scanner read the macro content type and fork differently if mandatory (and optional?) or no content type. Maybe these two levels are a bit far from each other... Paul
On Mon, Oct 5, 2015 at 1:09 AM, Paul Libbrecht <paul@hoplahup.net> wrote:
Hello Vincent,
What failed? Reading the content. I was just saying that our Confluence parser should support macros. I’ve just tried writing a page in Confluence syntax using an existing XWiki macro and it worked:
{html}<strong>hello</strong>{html} I can't explain why this one works but I presume there's a switch internally to it that automatically converts the html macro into a closing html macro (and indeed, it's nonsense to nest html). This worked too:
{documentTree} This worked too (showing we can pass one parameter): {documentTree:checkboxes=true} Yes, parameters reading (single and multiple) worked fine (but they need escaping).
I tried a tick more formally to see if I could make a macro with content and failed. Here's how.
Page: {testmacro} this is the content {testmacro}
Macro: (Tools.TestMacro, object XWiki.WikiMacroClass) id: testmacro inline: no (I tried yes too, with inlined macro in the page) visibility: global macro content type: optional macro code: testMacroStart{{velocity}}$!xcontext.macro.content{{/velocity}}testMacroEnd
The resulting page gives:
testMacroStarttestMacroEnd this is the content testMacroStarttestMacroEnd
I tried to adjust the content type to mandatory but this bragged... having no content!
If macro content was thinkable, then there should be somewhere in the grammar a different mark for start and end macro or? I don't see the latter.
No there is no special syntax, I guess in Confluence world macro handled are talling the parser which kind of macro they are during the parsing. In XWiki Confluence parser there is just a hardcoded list of known content macro right now and the default seems to be no content. We need to make it a bit more extensible.
Since, according to https://developer.atlassian.com/confdev/tutorials/macro-tutorials-for-conflu..., "there are three available body types for macros: PLAIN_TEXT, RICH_TEXT, and NONE. ", I suppose the only solution is to make the scanner read the macro content type and fork differently if mandatory (and optional?) or no content type. Maybe these two levels are a bit far from each other...
Paul _______________________________________________ users mailing list users@xwiki.org http://lists.xwiki.org/mailman/listinfo/users
-- Thomas Mortagne
Hi, On 5 Oct 2015 at 09:20:27, Thomas Mortagne (thomas.mortagne@xwiki.com(mailto:thomas.mortagne@xwiki.com)) wrote:
On Mon, Oct 5, 2015 at 1:09 AM, Paul Libbrecht wrote:
Hello Vincent,
What failed? Reading the content. I was just saying that our Confluence parser should support macros. I’ve just tried writing a page in Confluence syntax using an existing XWiki macro and it worked:
{html}hello{html} I can't explain why this one works but I presume there's a switch internally to it that automatically converts the html macro into a closing html macro (and indeed, it's nonsense to nest html). This worked too:
{documentTree} This worked too (showing we can pass one parameter): {documentTree:checkboxes=true} Yes, parameters reading (single and multiple) worked fine (but they need escaping).
I tried a tick more formally to see if I could make a macro with content and failed. Here's how.
Page: {testmacro} this is the content {testmacro}
Macro: (Tools.TestMacro, object XWiki.WikiMacroClass) id: testmacro inline: no (I tried yes too, with inlined macro in the page) visibility: global macro content type: optional macro code: testMacroStart{{velocity}}$!xcontext.macro.content{{/velocity}}testMacroEnd
The resulting page gives:
testMacroStarttestMacroEnd this is the content testMacroStarttestMacroEnd
I tried to adjust the content type to mandatory but this bragged... having no content!
If macro content was thinkable, then there should be somewhere in the grammar a different mark for start and end macro or? I don't see the latter.
No there is no special syntax, I guess in Confluence world macro handled are talling the parser which kind of macro they are during the parsing. In XWiki Confluence parser there is just a hardcoded list of known content macro right now and the default seems to be no content. We need to make it a bit more extensible.
Indeed, I was checking that at the same time as you did :) Paul, if you’re interested the grammar is in ConfluenceWikiScanner.jj and the list of macro which are defined to have content is: | <#MACRO_BLOCK: "{" ( "color" // TODO: {color:xx} paragraph {color} | "section" | "column" | "csv" | "table-plus" // TODO: {table-plus:width=100..} table {table-plus} | "code" | "html" | "composition-setup" | "float" // TODO: {float:xx} paragraph {float} | "cloak" | "deck" | "card" | "show-card" | "chart" // TODO: {chart: params} table {charŧ} | "slideshow" | "slide" | "note" | "warning" | "important" | "caution" | "example" | "docbook" | "screen" | "table-plus" | "info" | "tip" | "cache" | "sql" | "noformat" | "panel" | "sub-section" | "clickable" | "tm" // TODO: {tm} inline text {tm} | "sm" // TODO: {sm} inline text {sm} | "reg-tm" // TODO: {reg-tm} inline text {reg-tm} | "copyright" // TODO: {copyright} inline text {copyright} | "span" // TODO: {span} inline text {span} | "lozenge" | "style" | "div" | "bgcolor" | "center" | "strike" | "privacy-policy" | "roundrect" | "align" | "iframe" | "table" | "table-row" | "table-cell" | "th" | "tbody" | "thead" | "ul" | "li" | "rollover" | "fancy-bullets" | "contentformattingtest" | "toc-zone" | "excerpt" ) <MACRO_PARAMS> "}" > BTW, this is why my earlier example with {html} worked... So if you write a macro not in this list, it cannot currently have any content, only parameters. I’ve created http://jira.xwiki.org/browse/XRENDERING-412 Thanks -Vincent
Since, according to https://developer.atlassian.com/confdev/tutorials/macro-tutorials-for-conflu..., "there are three available body types for macros: PLAIN_TEXT, RICH_TEXT, and NONE. ", I suppose the only solution is to make the scanner read the macro content type and fork differently if mandatory (and optional?) or no content type. Maybe these two levels are a bit far from each other...
Paul
participants (3)
-
Paul Libbrecht -
Thomas Mortagne -
vincent@massol.net