Wiki source code of Export To Markdown
Version 4.1 by Tobias Wintrich on 2026/03/27 13:23
Show last authors
| author | version | line-number | content |
|---|---|---|---|
| 1 | {{groovy}} | ||
| 2 | import org.xwiki.model.reference.* | ||
| 3 | import java.io.File | ||
| 4 | |||
| 5 | if (request.confirm == '1') { | ||
| 6 | // Festes Export-Verzeichnis | ||
| 7 | def tmpDir = new File("/usr/local/xwiki/data/md-export") | ||
| 8 | tmpDir.mkdirs() | ||
| 9 | |||
| 10 | services.query.xwql( | ||
| 11 | "select distinct doc.fullName from Document doc " + | ||
| 12 | "where doc.space like 'HowTos' or doc.space like 'HowTos.%'" | ||
| 13 | ).execute().each() { | ||
| 14 | |||
| 15 | print "* Converting ${it} to MD..." | ||
| 16 | |||
| 17 | def itemDoc = xwiki.getDocument(it) | ||
| 18 | def newContent = services.rendering.render(itemDoc.getXDOM(), 'markdown/1.2') | ||
| 19 | |||
| 20 | def pathSerializer = services.component.getInstance( | ||
| 21 | EntityReferenceSerializer.TYPE_STRING, 'fspath' | ||
| 22 | ) | ||
| 23 | |||
| 24 | def outputFile = new File(tmpDir, pathSerializer.serialize(itemDoc.documentReference)) | ||
| 25 | outputFile.parentFile.mkdirs() | ||
| 26 | outputFile.text = newContent | ||
| 27 | |||
| 28 | println "Saved in ${outputFile.toString()}" | ||
| 29 | } | ||
| 30 | } | ||
| 31 | |||
| 32 | println "[[Export>>||queryString='confirm=1']]" | ||
| 33 | {{/groovy}} |