diff --git a/core/processor/src/main/java/io/quarkus/annotation/processor/documentation/config/formatter/JavadocToMarkdownTransformer.java b/core/processor/src/main/java/io/quarkus/annotation/processor/documentation/config/formatter/JavadocToMarkdownTransformer.java index 95b46d1ede4d1..f543e98e7ba41 100644 --- a/core/processor/src/main/java/io/quarkus/annotation/processor/documentation/config/formatter/JavadocToMarkdownTransformer.java +++ b/core/processor/src/main/java/io/quarkus/annotation/processor/documentation/config/formatter/JavadocToMarkdownTransformer.java @@ -47,6 +47,8 @@ public class JavadocToMarkdownTransformer { private static final Pattern URL_PATTERN = Pattern.compile("\\b(http[^\\[]+)\\[(.*?)\\]"); private static final Pattern XREF_PATTERN = Pattern.compile("xref:([^\\[]+)\\[(.*?)\\]"); private static final Pattern ICON_PATTERN = Pattern.compile("\\bicon:([a-z0-9_-]+)\\[(?:role=([a-z0-9_-]+))?\\](?=\\s|$)"); + private static final Pattern DESCRIPTION_LIST_PATTERN = Pattern.compile("^([a-z0-9][a-z0-9_ -]+)::(?=\\s|$)", + Pattern.CASE_INSENSITIVE | Pattern.MULTILINE); public static String toMarkdown(String javadoc, JavadocFormat format) { if (javadoc == null || javadoc.isBlank()) { @@ -326,6 +328,9 @@ private static String asciidocToMarkdown(String asciidoc) { // Convert icons markdownLine = convertIcons(markdownLine); + // Convert description lists: we only convert the title + markdownLine = convertDescriptionLists(markdownLine); + result.add(linePrefix + markdownLine); } @@ -387,4 +392,15 @@ private static String convertIcons(String line) { matcher.appendTail(sb); return sb.toString(); } + + private static String convertDescriptionLists(String line) { + Matcher matcher = DESCRIPTION_LIST_PATTERN.matcher(line); + StringBuffer sb = new StringBuffer(); + while (matcher.find()) { + String descriptionTitle = matcher.group(1); + matcher.appendReplacement(sb, "**" + descriptionTitle + "**"); + } + matcher.appendTail(sb); + return sb.toString(); + } } diff --git a/core/processor/src/test/java/io/quarkus/annotation/processor/documentation/config/formatter/AsciidocToMarkdownTransformerTest.java b/core/processor/src/test/java/io/quarkus/annotation/processor/documentation/config/formatter/AsciidocToMarkdownTransformerTest.java index 10b5138bab714..f0ab9d73c7013 100644 --- a/core/processor/src/test/java/io/quarkus/annotation/processor/documentation/config/formatter/AsciidocToMarkdownTransformerTest.java +++ b/core/processor/src/test/java/io/quarkus/annotation/processor/documentation/config/formatter/AsciidocToMarkdownTransformerTest.java @@ -169,4 +169,32 @@ public void testIcons() { assertEquals(expectedMarkdown, JavadocToMarkdownTransformer.toMarkdown(asciidoc, JavadocFormat.ASCIIDOC)); } + + @Test + public void testDescriptionLists() { + String asciidoc = """ + This is a simple paragraph. + + Item title1:: item description 1 + Item title2:: item description 2 + + Item title1:: + Item description 1 + + Item title2:: + Item description 2"""; + String expectedMarkdown = """ + This is a simple paragraph. + + **Item title1** item description 1 + **Item title2** item description 2 + + **Item title1** + Item description 1 + + **Item title2** + Item description 2"""; + + assertEquals(expectedMarkdown, JavadocToMarkdownTransformer.toMarkdown(asciidoc, JavadocFormat.ASCIIDOC)); + } }