Convert Confluence to XWiki Syntax

Last modified by Vincent Massol on 2021/03/18 11:28

cogConverts some content in Confluence wiki markup into XWiki Syntax 2.1 markup
TypeSnippet
Category
Developed by

Vincent Massol

Rating
0 Votes
LicenseGNU Lesser General Public License 2.1

Table of contents

Description

Notes:

  • Note 1: Since Confluence now uses HTML as the internal format you can use the same script to convert from HTML to XWiki Syntax
  • Note 2: XWiki supports several syntaxes natively so you don't need to convert, except that the XWik Syntax is the most complete one and can be used without loss with the XWiki WYSIWYG editor (see PageEditing).
  • Note 3: There's now a Confluence Importer
{{groovy}}
import com.xpn.xwiki.web.Utils
import org.xwiki.rendering.renderer.printer.*
import org.xwiki.rendering.converter.*
import org.xwiki.rendering.syntax.*

// Read Confluence Content (You can get it from wherever you wish: local file, web page, etc)
def content = """
h1. Biggest heading
Hello *bold* world
"""


// Convert to XWiki 2.1 Syntax
def converter =  services.component.getInstance(Converter.class);
def printer = new DefaultWikiPrinter();
converter.convert(new StringReader(content), Syntax.CONFLUENCE_1_0, Syntax.XWIKI_2_1, printer);
def newContent = printer.toString()

// Create new Document with converted content
def newDoc = xwiki.getDocument("Main.NewDoc")
newDoc.setContent(newContent)
newDoc.save()
{{/groovy}}
     

Get Connected