1 minute to read
convertToEpub
At a Glance
Dependency
About This Task
This task uses pandoc to convert the DocBook output from AsciiDoctor to ePub.
This publishes the output as an eBook which can be read using any eBook reader.
The resulting file can be found in build/docs/epub
.
Further Reading and Resources
Turn your Document into an Audio-Book blog post.
Source
pandoc.gradle
task convertToEpub (
group: 'docToolchain',
description: 'converts file to .epub via pandoc. Needs pandoc installed.',
type: Exec
) {
// All files with option `epub` in config.groovy is converted to docbook and then to epub.
def sourceFilesEpub = sourceFiles.findAll { 'epub' in it.formats }
def explicitSourceFilesCount = sourceFilesEpub.size()
if(explicitSourceFilesCount==0){
sourceFilesEpub = sourceFiles.findAll { 'docbook' in it.formats }
}
sourceFilesEpub.each {
def sourceFile = it.file.replace('.adoc', '.xml')
def targetFile = sourceFile.replace('.xml', '.epub')
new File("$targetDir/epub/$targetFile")
.getParentFile()
.getAbsoluteFile().mkdirs()
workingDir "$targetDir/docbook"
executable = "pandoc"
args = ['-r','docbook',
'-t','epub',
'-o',"../epub/$targetFile",
sourceFile]
}
doFirst {
if(sourceFilesEpub.size()==0){
throw new Exception ("""
>> No source files defined for type 'epub'.
>> Please specify at least one inputFile in your docToolchainConfig.groovy
""")
}
if(explicitSourceFilesCount==0) {
logger.warn('WARNING: No source files defined for type "epub". Converting with best effort')
}
}
}
Feedback
Was this page helpful?
Glad to hear it! Please tell us how we can improve.
Sorry to hear that. Please tell us how we can improve.