summaryrefslogtreecommitdiff
path: root/docs/modules/migrate/examples
diff options
context:
space:
mode:
authorSarah White <graphitefriction@gmail.com>2020-11-18 15:53:10 -0700
committerSarah White <graphitefriction@gmail.com>2020-12-08 14:32:53 -0700
commitc3c7ddbda681cc8f44832b0549bb623d3eace748 (patch)
tree06d5d290d15b2f71758c40efca08d587e9e691b8 /docs/modules/migrate/examples
parentcd241bc19e5016468e24104f949f0d18f207c69b (diff)
rearchitect modules and filenames and drop asciidoctor folder under docs
Diffstat (limited to 'docs/modules/migrate/examples')
-rw-r--r--docs/modules/migrate/examples/convert.groovy43
1 files changed, 43 insertions, 0 deletions
diff --git a/docs/modules/migrate/examples/convert.groovy b/docs/modules/migrate/examples/convert.groovy
new file mode 100644
index 00000000..6dba705c
--- /dev/null
+++ b/docs/modules/migrate/examples/convert.groovy
@@ -0,0 +1,43 @@
+// This script is provided by melix.
+// The source can be found at https://gist.github.com/melix/6020336
+
+@Grab('net.sourceforge.htmlcleaner:htmlcleaner:2.4')
+import org.htmlcleaner.*
+
+def src = new File('html').toPath()
+def dst = new File('asciidoc').toPath()
+
+def cleaner = new HtmlCleaner()
+def props = cleaner.properties
+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()) {
+ target.toFile().mkdir()
+ } else if (f.name.endsWith('.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) {
+ tagNode.name='td'
+ String txt = tagNode.text
+ tagNode.removeAllChildren()
+ tagNode.insertChild(0, new ContentNode(txt))
+ }
+
+ true
+ } as TagNodeVisitor)
+ serializer.writeToFile(
+ result, tmpHtml.absolutePath, "utf-8"
+ )
+ "pandoc -f html -t asciidoc -R -S --normalize -s $tmpHtml -o ${target}.adoc".execute().waitFor()
+ tmpHtml.delete()
+ }/* else {
+ "cp html/$relative $target".execute()
+ }*/
+}