Reducing AsciiDoc includes to single files with Asciidoctor Reducer

With the 5.0 release, there is now the ability to reduce AsciiDoc files which include other files into a single AsciiDoc files using Asciidoctor Reducer This toolchain does not use any of the Asciidoctor engines underneath, but it provides its own pnpm-based toolchain.

  • Groovy

import org.asciidoctor.gradle.model5.reducer.toolchains.AsciidoctorReducerToolchain
import org.asciidoctor.gradle.model5.reducer.formatters.AsciidoctorReducerOutputFormatter

asciidoc {
    toolchains {
        asciidoctorReducer(AsciidoctorReducerToolchain) { (1)

            safeMode = 'unsafe' (2)

            useReducer( '1.2.3' ) (3)
            useJRuby( '9.1.2.3' ) (4)

            engineOptions {
                trace = true (5)
            }

            registeredOutputFormatters {
                reducedAdoc(AsciidoctorReducerOutputFormatter) { (6)
                    preserveConditionals = true (7)
                }
            }

            forkOptions { (8)
            }

            forkEvery = 10 (9)
        }
    }

  publications {
    main {
        output 'asciidoctorReducer', 'reducedAdoc' (10)
    }

  }
}
1 The default toolchain is called asciidoctorReducer
2 Set the safe mode. Default is unsafe.
3 Override the default version of Asciidoctor Reducer.
4 Whether to turn on tracing.
5 Override the default version of JRuby.
6 The default formatter is called reducedAdoc.
7 Whether conditional directives should be kept. Default is false.
8 All workers for this toolchain runs process-isolated. Configure the fork options for these workers if the defaults do not work for you.
9 Set the ability to fork a new worker every X documents. This might be useful in cases where many documents need to be processed. Setting it to 0 (the default) means that all documents will be processed in the worker.
10 Create an output that will take Asciidoc as input as produce reduced Asciidoc documents.