asciidoc2confluence icon indicating copy to clipboard operation
asciidoc2confluence copied to clipboard

a groovy script to export an HTML file generated by asciidoc to several confluence pages

[NOTE]

The code has been transfered to https://github.com/docToolchain/docToolchain/blob/master/scripts/asciidoc2confluence.groovy

it is now part of docToolchain

= asciidoc2confluence :toc: :includedir: ./ :source-highlighter: coderay

This is a groovy script to import HTML files generated by http://asciidoctor.org/[asciidoctor] to one or multiple https://www.atlassian.com/software/confluence/[Confluence] pages.

== Features

  • splits large asciidoc documents in to several confluence pages. This is useful if you need to use the confluence comments for feedback
  • checks if pages need to be updated and only updates those in order to have a clean history and to avoid sending out unnecassary notifications
  • converts some asciidoc features to confluence macros (admonitions, code)
  • cleans up the asciidoc generated HTML to better fit the confluence storage format
  • displays errors from the confluence API

== Usage

The easiest way to get this up and running is to modify the Config.groovy to fit your environment and load the main script into the groovyConsole. You then need some HTML output from http://asciidoctor.org/[asciidoctor] (The https://raw.githubusercontent.com/arc42/arc42.github.io/master/template/en/arc42-template.html[arc42 template] might be a good starting point, the http://aim42.github.io/htmlSanityCheck/hsc_arc42.html[HTML Sanity Checker Architecture Documentation] is even better :-). Please note that the script is completely focussed on Asciidoctor output as it makes assumptions about the HTML structure (e.g. "sect1" and "sect2" css classes being present).

When you start the script the first time, it will try to split the html file into subsections and push them to your confluence instance. This is done to be able to handle large documentation pages and to be able to send update notifications for specific sections of a large document. This can be switched off though by the confluenceCreateSubpages configuration parameter.

== Configuration

[source,groovy] .Config.groovy

include::Config.groovy[]

== Running the script

The script can be run directly, via Maven or Gradle. It requires Java >= 7 and the scriptBasePath variable being set which points to the folder where to find the Config.groovy file.

=== Usage with Maven

The following pom.xml sample shows how to use the asciidoc2confluence.groovy script with your Maven build. It will run when you execute the mvn gplus:execute goal.

[source,xml,linenums]

4.0.0 io.github.rdmueller asciidoc2confluence 1.0.0-SNAPSHOT jar asciidoc2confluence sample An asciidoc2confluence sample pom.xml UTF-8 1.8 1.8 1.8 ${project.artifactId} org.apache.maven.plugins maven-compiler-plugin ${java.target.version} ${java.source.version} org.codehaus.gmavenplus gmavenplus-plugin 1.5 execute scriptBasePath ${project.basedir}/src/main/groovy/ org.codehaus.groovy groovy-all 2.4.3 runtime ----

=== Usage with Gradle

The following build.gradle sample shows how to use the asciidoc2confluence.groovy script with your Gradle build. It will run when you execute the gradle task gradlew publishToConfluence.


buildscript { dependencies { //for the exportJiraIssues Task classpath 'org.codehaus.groovy.modules.http-builder:http-builder:0.6' //for the renderToConfluence Task classpath 'org.apache.httpcomponents:httpmime:4.3.1' classpath 'org.jsoup:jsoup:1.9.1' } repositories { jcenter() } }

task publishToConfluence( description: 'publishes the HTML rendered output to confluence', group: 'docToolchain' ) { // Directory containing the documents to be processed by docToolchain. // If the documents are together with docToolchain, this can be relative path. // If the documents are outside of docToolchain, this must be absolute path, usually provided // on the command line with -P option given to gradle. def docDir = file('.').path

def confluenceConfigFile = "scripts/ConfluenceConfig.groovy"
def confluenceScript = project.file('scripts/asciidoc2confluence.groovy')

doLast {
    binding.setProperty('docDir', docDir)
    binding.setProperty('confluenceConfigFile', confluenceConfigFile)
    evaluate(confluenceScript)
}

}