From f0c00083746209028d075e5c7fe49e01e50f8644 Mon Sep 17 00:00:00 2001 From: Ben Soares Date: Fri, 29 Apr 2022 13:29:17 +0100 Subject: [PATCH] JAL-3989 small improvements to output markdown --- build.gradle | 67 ++++++++++++++++++++++++++++++++++++++++------------------ 1 file changed, 47 insertions(+), 20 deletions(-) diff --git a/build.gradle b/build.gradle index 79fb2d9..69bc51c 100644 --- a/build.gradle +++ b/build.gradle @@ -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 { } } + } } } -- 1.7.10.2