|
5 | 5 | //DEPS io.quarkus:quarkus-picocli |
6 | 6 | //DEPS io.quarkus:quarkus-smallrye-graphql-client |
7 | 7 | //DEPS io.quarkus:quarkus-qute |
8 | | -//DEPS org.commonmark:commonmark:0.22.0 |
| 8 | +//DEPS org.commonmark:commonmark:0.23.0 |
9 | 9 | //DEPS io.quarkus:quarkus-config-yaml |
10 | 10 | //FILES templates/=templates/* |
11 | 11 | //FILES application.yaml |
|
26 | 26 | import java.util.concurrent.ExecutionException; |
27 | 27 |
|
28 | 28 | import org.commonmark.node.Node; |
| 29 | +import org.commonmark.node.Paragraph; |
29 | 30 | import org.commonmark.parser.Parser; |
30 | 31 | import org.commonmark.renderer.html.HtmlRenderer; |
31 | 32 | import org.eclipse.microprofile.config.inject.ConfigProperty; |
@@ -198,6 +199,71 @@ public String getReadme() { |
198 | 199 | return renderer.render(document); |
199 | 200 | } |
200 | 201 |
|
| 202 | + private static boolean isMetadata(String singular, String plural, String line) { |
| 203 | + var l = line.toLowerCase().trim(); |
| 204 | + return l.startsWith("* " + singular.toLowerCase() + ":") |
| 205 | + || l.startsWith("* " + plural.toLowerCase() + ":"); |
| 206 | + } |
| 207 | + |
| 208 | + public String getDeliverable() { |
| 209 | + String line = longDescription().lines() |
| 210 | + .filter(s -> isMetadata("Deliverable", "Deliverables", s)) |
| 211 | + .findFirst() |
| 212 | + .orElse(null); |
| 213 | + |
| 214 | + if (line != null) { |
| 215 | + var content = line.substring(line.indexOf(":") + 1).trim(); |
| 216 | + Parser parser = Parser.builder().build(); |
| 217 | + Node document = parser.parse(content); |
| 218 | + HtmlRenderer renderer = HtmlRenderer.builder() |
| 219 | + .omitSingleParagraphP(true) |
| 220 | + .escapeHtml(false) |
| 221 | + .sanitizeUrls(true) |
| 222 | + .build(); |
| 223 | + return renderer.render(document); |
| 224 | + } |
| 225 | + |
| 226 | + return null; |
| 227 | + } |
| 228 | + |
| 229 | + public String getPointOfContact() { |
| 230 | + String line = longDescription().lines() |
| 231 | + .filter(s -> isMetadata("Point of contact", "Points of contact", s)) |
| 232 | + .findFirst() |
| 233 | + .orElse(null); |
| 234 | + |
| 235 | + if (line != null) { |
| 236 | + var content = line.substring(line.indexOf(":") + 1).trim(); |
| 237 | + Parser parser = Parser.builder().build(); |
| 238 | + Node document = parser.parse(content); |
| 239 | + HtmlRenderer renderer = HtmlRenderer.builder() |
| 240 | + .omitSingleParagraphP(true) |
| 241 | + .build(); |
| 242 | + return renderer.render(document); |
| 243 | + } |
| 244 | + |
| 245 | + return null; |
| 246 | + } |
| 247 | + |
| 248 | + public String getDiscussionLink() { |
| 249 | + String line = longDescription().lines() |
| 250 | + .filter(s -> isMetadata("Discussion", "Discussions", s)) |
| 251 | + .findFirst() |
| 252 | + .orElse(null); |
| 253 | + |
| 254 | + if (line != null) { |
| 255 | + var content = line.substring(line.indexOf(":") + 1).trim(); |
| 256 | + Parser parser = Parser.builder().build(); |
| 257 | + Node document = parser.parse(content); |
| 258 | + HtmlRenderer renderer = HtmlRenderer.builder() |
| 259 | + .omitSingleParagraphP(true) |
| 260 | + .build(); |
| 261 | + return renderer.render(document); |
| 262 | + } |
| 263 | + |
| 264 | + return null; |
| 265 | + } |
| 266 | + |
201 | 267 | public String getIndentedReadme() { |
202 | 268 | String readme = getReadme(); |
203 | 269 | return readme.replaceAll("\n", "\n ").trim(); |
|
0 commit comments