Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Convert Confluence HTML export into asciidoc
import org.htmlcleaner.*
def src = new File('html').toPath()
def dst = new File('asciidoc').toPath()
def cleaner = new HtmlCleaner()
def props =
props.translateSpecialEntities = false
def serializer = new SimpleHtmlSerializer(props)
src.toFile().eachFileRecurse { f ->
def relative = src.relativize(f.toPath())
def target = dst.resolve(relative)
if (f.isDirectory()) {
} else if ('.html')) {
def tmpHtml = File.createTempFile('clean', 'html')
println "Converting $relative"
def result = cleaner.clean(f)
result.traverse({ tagNode, htmlNode ->
tagNode?.attributes?.remove 'class'
if ('td' == tagNode?.name || 'th'==tagNode?.name) {'td'
String txt = tagNode.text
tagNode.insertChild(0, new ContentNode(txt))
} as TagNodeVisitor)
result, tmpHtml.absolutePath, "utf-8"
"pandoc -f html -t asciidoc -R -S --normalize -s $tmpHtml -o ${target}.adoc".execute().waitFor()
}/* else {
"cp html/$relative $target".execute()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment