Wiki source code of Export To Markdown
Version 4.1 by Tobias Wintrich on 2026/03/27 13:23
Hide last authors
| author | version | line-number | content |
|---|---|---|---|
| |
2.1 | 1 | {{groovy}} |
| |
1.1 | 2 | import org.xwiki.model.reference.* |
| |
4.1 | 3 | import java.io.File |
| |
1.1 | 4 | |
| 5 | if (request.confirm == '1') { | ||
| |
4.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 | |||
| |
1.1 | 15 | print "* Converting ${it} to MD..." |
| |
4.1 | 16 | |
| |
1.1 | 17 | def itemDoc = xwiki.getDocument(it) |
| 18 | def newContent = services.rendering.render(itemDoc.getXDOM(), 'markdown/1.2') | ||
| |
4.1 | 19 | |
| 20 | def pathSerializer = services.component.getInstance( | ||
| 21 | EntityReferenceSerializer.TYPE_STRING, 'fspath' | ||
| 22 | ) | ||
| 23 | |||
| |
1.1 | 24 | def outputFile = new File(tmpDir, pathSerializer.serialize(itemDoc.documentReference)) |
| 25 | outputFile.parentFile.mkdirs() | ||
| |
4.1 | 26 | outputFile.text = newContent |
| 27 | |||
| |
1.1 | 28 | println "Saved in ${outputFile.toString()}" |
| 29 | } | ||
| 30 | } | ||
| 31 | |||
| 32 | println "[[Export>>||queryString='confirm=1']]" | ||
| |
2.1 | 33 | {{/groovy}} |