asciidoctor / asciidoctor-gradle-plugin

A Gradle plugin that uses Asciidoctor via JRuby to process AsciiDoc source files within the project.
https://asciidoctor.github.io/asciidoctor-gradle-plugin/
Apache License 2.0
285 stars 120 forks source link

Support extending the default style sheet #674

Closed micheljung closed 1 year ago

micheljung commented 1 year ago

From Extend the default stylesheet:

Now tell Asciidoctor to use your custom stylesheet instead of the default one:

asciidoctor -a stylesheet=my-asciidoctor.css document.adoc

Asciidoctor will now embed the contents of your custom stylesheet instead of the default one. However, Asciidoctor will not embed the contents of the default stylesheet. Instead, the browser will fetch it from the location specified by the @import directive. You can avoid this network call by putting the default stylesheet in the same directory as your custom stylesheet and linking to it using @import "asciidoctor.css".

However, if you put asciidoctor.css next to your stylesheet, the plugin will not copy it to build/docs/asciidoc thus it is not accessible by the browser.

micheljung commented 1 year ago

This solves the issue:

tasks {
tasks {
  "asciidoctor"(org.asciidoctor.gradle.jvm.AsciidoctorTask::class) {
    setBaseDir(sourceDir)

    resources(delegateClosureOf<CopySpec> {
      from("src/docs/asciidoc/style") {
        include("*.css")
        exclude("my-asciidoctor.css")
      }

      into("./")
    })

    attributes(
      mapOf(
        "stylesdir" to "style",
        "stylesheet" to "my-asciidoctor.css",
      ),
    )
  }
}