George
June 14, 2023, 9:32pm
1
Hi!
I need to export source code of page.
I found discuss
Where there is example of groovy script to export page to markdown
But when I change in this script
'markdown/1.2'
to xwiki/2.1
script create empty files with ‘null’ inside
Could any one tell how I need to change script to download source code as is.
All my pages are in Xwiki/2.1 syntax.
As is but with rendered macros on pages.
So if your pages are already in xwiki/2.1 syntax this script is really not what you need since the main point of this script is to do syntax conversion. That means that itemDoc.content
is enough to get the content of the page in syntax xwiki/2.1.
It’s not very clear to me what you want to do with it, as it might have an impact on how to export the content. For example, if your pages contains xwiki/2.1 content then you could simply use the XAR export which simply produce a zip file containing an XML for each page with the content in it.
1 Like
George
June 15, 2023, 7:29am
3
Hello!
I have the following use case:
User selects pages to export within XWiki.
User presses a button to generate a DOCX with custom template (need to apply custom styles).
XWiki exports selected pages in xwiki/2.1 syntax
System passes pages to pandoc.
Pandoc creates a DOCX file using custom LUA filter and template from user.
For first step I need to create zip with selected pages in xwiki/2.1 syntax.
And I XML format is not suitable for me;
This variant is working for me
{{groovy}}
import org.xwiki.environment.*
import org.xwiki.model.reference.*
if (request.confirm == '1') {
services.query.xwql("select distinct doc.fullName from Document doc where doc.space like 'Sandbox' or doc.space like 'Sandbox.%'").execute().each() {
print "* Converting ${it} to MD..."
def itemDoc = xwiki.getDocument(it)
def newContent = itemDoc.getContent()
def tmpDir = new File(services.component.getInstance(Environment.class).temporaryDirectory, 'md-export')
def pathSerializer = services.component.getInstance(EntityReferenceSerializer.TYPE_STRING, 'fspath')
def outputFile = new File(tmpDir, pathSerializer.serialize(itemDoc.documentReference))
outputFile.parentFile.mkdirs()
outputFile << newContent
println "Saved in ${outputFile.toString()}"
}
}
println "[[Export>>||queryString='confirm=1']]"
{{/groovy}}
Glad you found a solution for your use case
1 Like