Skip to content

Commit

Permalink
Config Doc - Handle simple description lists in adoc -> md conversion
Browse files Browse the repository at this point in the history
Related to quarkusio#43287
  • Loading branch information
gsmet committed Sep 30, 2024
1 parent 42298c2 commit 1bcc0a1
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand Down Expand Up @@ -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);
}

Expand Down Expand Up @@ -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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
}

0 comments on commit 1bcc0a1

Please sign in to comment.