Converting HTML to Xwiki 2.1

Hi xwiki Team,

I’m working on a Migration from an older wiki system to the xwiki.
The other wiki uses HTML as syntax.
So I want to convert all my pages from HTML to xwiki Syntax.
I’m searching for a endpoint that let me convert HTML to xwiki Syntax.
I saw that I can activate HTML as a wiki Syntax and than just changing the syntax by selecting xwiki in the Syntax Dropdown of the Page.
I tried to recreated that call but I didn’t fully understand it.
So what is the best way to do that?
Oh and I’m running xwiki 13.1

thanks for your help

Aaron

yes xwiki can use html as wiki page syntax. To set that, see https://www.xwiki.org/xwiki/bin/view/Documentation/UserGuide/Features/PageEditing#HChoosingaSyntax

Note that you probably want to install the HTML 4.01 syntax extension and use that instead if XHML which is more strict.

thanks for your quick reply,

I already converted HTML to xwiki Syntax manually.
But my question is if there is an API call to automate the Conversion.
Our current wiki has about 10,000 pages, so of course we don’t wan to convert those pages manually.

We don’t have an HTML importer ATM and I agree it would be nice to have it. See also Loading...

Right now what you can do is write a small script in a wiki page (or in java if you prefer) to iterate over all the pages and call the rendering script service api to do the conversion. For example to convert from one syntax to another: https://rendering.xwiki.org/xwiki/bin/view/Main/GettingStarted#HRenderXWikiSyntax2.1contentintoXHTML

Then you need to use the xwiki api to create a wiki page and set the content to be the converted content, that’s quite easy. See https://www.xwiki.org/xwiki/bin/view/Documentation/DevGuide/Scripting/APIGuide/#HCreateanewDocument

Ok, thanks for that advice.
I already tried to write a Java Program which is using the xwiki-rendering-engine and after the conversion, it will create the pages using the HTTP API.
Unfortunately I always got a “Failed to locate Parser for syntax [HTML 4.01]” message.

Would that be a possible way and to you have any idea about the error? I used the following dependencies

pom.txt (1.7 KB)

Could you show your code?

sure, there isn’t that much code :wink:

public static void main( String[] args )
    {
        LocalConverter localConverter = new LocalConverter();
        System.out.println(localConverter.HTML2XWiki("\<h1>Caption\</h1>"));
       
    }

LocalConverter.txt (1.2 KB)

PS: please use markdown backticks for code…

At first sight you code looks good to me.

Maybe avoid using different XWiki versions in your dependencies but that shouldn’t matter that much between 13.1 and 13.2

Thanks again for your help.

Did you have a change to try my code? I tried it again and I still getting the
“Failed to locate Renderer for syntax [HTML 4.01]” error Message.

I also tried to write a script, but I always end up with an error saying “Nested scripts are not allowed.”
It might be a permission problem, but I wasn’t able to figure it out.

err

That’s because you’re not allow to nest scripts. Just don’t nest them :wink: It’s hard to help you more without seeing your code.

so?

I tried it. I was setting all versions to 13.2 but I still got the same error.

I’m not sure what Nested Scripts mean. I just created a new Page and added an example Script.
I just wanted to get familiar with the Scripting API.
clicking the plus in the Editor → selecting ‘other Marcos’ → selected Velocity → and pasted a Code Snippet from the Scripting Doc
https://www.xwiki.org/xwiki/bin/view/Documentation/DevGuide/Scripting/APIGuide/.

And after saving the page I got the error