Wiki source code of Export To Markdown
Version 3.1 by René Vögeli on 2026/03/25 10:32
Show last authors
| author | version | line-number | content |
|---|---|---|---|
| 1 | {{groovy}} | ||
| 2 | import org.xwiki.environment.* | ||
| 3 | import org.xwiki.model.reference.* | ||
| 4 | |||
| 5 | if (request.confirm == '1') { | ||
| 6 | services.query.xwql("select distinct doc.fullName from Document doc where doc.space like 'HowTos' or doc.space like 'HowTos.%'").execute().each() { | ||
| 7 | print "* Converting ${it} to MD..." | ||
| 8 | def itemDoc = xwiki.getDocument(it) | ||
| 9 | def newContent = services.rendering.render(itemDoc.getXDOM(), 'markdown/1.2') | ||
| 10 | def tmpDir = new File(services.component.getInstance(Environment.class).temporaryDirectory, 'md-export') | ||
| 11 | def pathSerializer = services.component.getInstance(EntityReferenceSerializer.TYPE_STRING, 'fspath') | ||
| 12 | def outputFile = new File(tmpDir, pathSerializer.serialize(itemDoc.documentReference)) | ||
| 13 | outputFile.parentFile.mkdirs() | ||
| 14 | outputFile << newContent | ||
| 15 | println "Saved in ${outputFile.toString()}" | ||
| 16 | } | ||
| 17 | } | ||
| 18 | |||
| 19 | println "[[Export>>||queryString='confirm=1']]" | ||
| 20 | {{/groovy}} |