JAL-3989 small improvements to output markdown
authorBen Soares <bsoares@dundee.ac.uk>
Fri, 29 Apr 2022 12:29:17 +0000 (13:29 +0100)
committerBen Soares <bsoares@dundee.ac.uk>
Fri, 29 Apr 2022 12:29:17 +0000 (13:29 +0100)
build.gradle

index 79fb2d9..69bc51c 100644 (file)
@@ -27,6 +27,7 @@ import com.google.common.hash.HashCode
 import com.google.common.hash.Hashing
 import com.google.common.io.Files
 import org.jsoup.Jsoup
+import org.jsoup.nodes.Element
 
 buildscript {
   repositories {
@@ -2400,6 +2401,45 @@ def hugoTemplateSubstitutions(String input) {
   return output
 }
 
+def ulToList(Element ul, int indent) {
+  def list = ""
+  ul.children().each { e ->
+    if (e.tagName().toLowerCase() == "ul") {
+      list += "\n"
+      list += ulToList(e, indent+1)
+    } else if (e.tagName().toLowerCase() == "li") {
+      def issues = []
+      def mdItem = "  " * indent + "- "
+      e.childNodes().any {n ->
+        if (n.nodeName().equals("#comment")) {
+          mdItem += "${n} "
+          issues = n.getData().trim().split(/[,\s]+/)
+          return true
+        }
+      }
+      def issuesLink = (issues.size() > 0) ?
+        " {{< jal issue=\"${issues.join(",")}\" >}}"
+        : ""
+      def addedIssues = false
+      e.childNodes().each { node ->
+        if (node.nodeName().toLowerCase() == "ul") {
+          // add issues link before sub list
+          mdItem += "${issuesLink}\n"
+          addedIssues = true
+          mdItem += ulToList(e, indent+1)
+        } else if (node.nodeName() == "#text") {
+          mdItem += node.text()
+        }
+      }
+      if (!addedIssues) {
+        mdItem += issuesLink
+      }
+      list += "${mdItem}\n"
+    }
+  }
+  return list
+}
+
 task hugoTemplates {
   group "website"
   description "Create partially populated md pages for hugo website build"
@@ -2481,27 +2521,13 @@ task hugoTemplates {
               def noheadings = true
               releaseCells[col].children().each { e ->
                 if (e.tagName().toLowerCase() == "ul") {
-                  e.select("li").each { li ->
-                    def issues = []
-                    def mdItem = "- "
-                    li.childNodes().any {n ->
-                      if (n.nodeName().equals("#comment")) {
-                        mdItem += "${n} "
-                        issues = n.getData().trim().split(/[,\s]+/)
-                        return true
-                      }
-                    }
-                    mdItem += li.text()
-                    issues.each { jal ->
-                      mdItem += " {{< jal issue=\"${jal}\" >}}"
-                    }
-                    if (noheadings) {
-                      changes += "\n### ${headings[1]}\n\n"
-                      noheadings = false
-                    }
-                    changes += "${mdItem}\n"
+                  def list = ulToList(e, 0)
+                  if (noheadings && list != "") {
+                    changes += "\n### ${headings[col]}\n\n"
+                    noheadings = false
                   }
-                } else if (e.tag() == "em") {
+                  changes += list
+                } else if (e.tagName().toLowerCase() == "em") {
                   changes += "\n#### ${e.text()}\n\n"
                   noheadings = false
                 }
@@ -2509,6 +2535,7 @@ task hugoTemplates {
             }
           }
 
+
         }
       }
     }