This is an automated email from the ASF dual-hosted git repository.
slachiewicz pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/maven-doxia-converter.git
The following commit(s) were added to refs/heads/master by this push:
new e1a33e5 Detect Markdown input by the .markdown extension too
e1a33e5 is described below
commit e1a33e59fd6644ea9d604acb85be133b521ee3ba
Author: Sylwester Lachiewicz <[email protected]>
AuthorDate: Tue Nov 3 21:52:03 2026 +0000
Detect Markdown input by the .markdown extension too
---
.../org/apache/maven/doxia/DefaultConverter.java | 50 +++++++++++++++++-----
.../java/org/apache/maven/doxia/ConverterTest.java | 10 +++++
src/test/resources/unit/markdown/test.markdown | 3 ++
src/test/resources/unit/markdown/test.md | 3 ++
4 files changed, 55 insertions(+), 11 deletions(-)
diff --git a/src/main/java/org/apache/maven/doxia/DefaultConverter.java
b/src/main/java/org/apache/maven/doxia/DefaultConverter.java
index 2ad4326..0a33920 100644
--- a/src/main/java/org/apache/maven/doxia/DefaultConverter.java
+++ b/src/main/java/org/apache/maven/doxia/DefaultConverter.java
@@ -37,6 +37,8 @@ import java.nio.charset.Charset;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.StandardCopyOption;
+import java.util.ArrayList;
+import java.util.Arrays;
import java.util.EnumSet;
import java.util.HashMap;
import java.util.LinkedHashMap;
@@ -45,6 +47,7 @@ import java.util.Locale;
import java.util.Map;
import java.util.Objects;
import java.util.Scanner;
+import java.util.StringJoiner;
import java.util.stream.Collectors;
import com.ibm.icu.text.CharsetDetector;
@@ -162,12 +165,14 @@ public class DefaultConverter implements Converter {
FML("fml", "fml", "faqs", true, false),
XDOC("xdoc", "xml", "document", true, true),
XHTML("xhtml", "html", "html", true, true),
- MARKDOWN("markdown", "md", true, true);
+ MARKDOWN("markdown", "md", null, true, true, "markdown");
/** Plexus role hint for Doxia sink/parser */
private final String roleHint;
private final String extension;
+ /** Further extensions recognized for input files */
+ private final String[] alternativeExtensions;
/** The name of the first element in case this is an XML format,
otherwise {@code null} */
private final String firstElement;
@@ -178,9 +183,16 @@ public class DefaultConverter implements Converter {
this(roleHint, extension, null, hasParser, hasSink);
}
- DoxiaFormat(String roleHint, String extension, String firstElement,
boolean hasParser, boolean hasSink) {
+ DoxiaFormat(
+ String roleHint,
+ String extension,
+ String firstElement,
+ boolean hasParser,
+ boolean hasSink,
+ String... alternativeExtensions) {
this.roleHint = roleHint;
this.extension = extension;
+ this.alternativeExtensions = alternativeExtensions;
this.firstElement = firstElement;
this.hasParser = hasParser;
this.hasSink = hasSink;
@@ -194,6 +206,17 @@ public class DefaultConverter implements Converter {
return extension;
}
+ /**
+ *
+ * @return the primary extension followed by any further extensions
recognized for input files
+ */
+ public List<String> getExtensions() {
+ List<String> extensions = new ArrayList<>();
+ extensions.add(extension);
+ extensions.addAll(Arrays.asList(alternativeExtensions));
+ return extensions;
+ }
+
public boolean hasParser() {
return hasParser;
}
@@ -305,8 +328,10 @@ public class DefaultConverter implements Converter {
return format;
}
} else {
- if (hasFileExtensionIgnoreCase(f.getName(),
format.getExtension())) {
- return format;
+ for (String extension : format.getExtensions()) {
+ if (hasFileExtensionIgnoreCase(f.getName(),
extension)) {
+ return format;
+ }
}
}
}
@@ -354,7 +379,7 @@ public class DefaultConverter implements Converter {
try {
files = FileUtils.getFiles(
input.getFile(),
- getFileNamePatterns(input.getFormat().getExtension(),
!input.isExcludeVelocityTemplates()),
+ getFileNamePatterns(input.getFormat().getExtensions(),
!input.isExcludeVelocityTemplates()),
StringUtils.join(FileUtils.getDefaultExcludes(), ",
"));
} catch (IOException e) {
throw new ConverterException("IOException: " + e.getMessage(),
e);
@@ -363,7 +388,8 @@ public class DefaultConverter implements Converter {
}
if (files.isEmpty()) {
throw new ConverterException("ConverterException: No files
with extension "
- + input.getFormat().getExtension() + " found in
directory " + input.getFile());
+ + String.join(", ", input.getFormat().getExtensions())
+ " found in directory "
+ + input.getFile());
}
for (File f : files) {
File relativeOutputDirectory =
@@ -381,11 +407,13 @@ public class DefaultConverter implements Converter {
}
}
- static String getFileNamePatterns(String extension, boolean
includeVelocityTemplates) {
- StringBuilder patterns = new StringBuilder("**/*." + extension);
- if (includeVelocityTemplates) {
- patterns.append(",");
-
patterns.append("**/*.").append(extension).append(VELOCITY_TEMPLATE_EXTENSION);
+ static String getFileNamePatterns(List<String> extensions, boolean
includeVelocityTemplates) {
+ StringJoiner patterns = new StringJoiner(",");
+ for (String extension : extensions) {
+ patterns.add("**/*." + extension);
+ if (includeVelocityTemplates) {
+ patterns.add("**/*." + extension +
VELOCITY_TEMPLATE_EXTENSION);
+ }
}
return patterns.toString();
}
diff --git a/src/test/java/org/apache/maven/doxia/ConverterTest.java
b/src/test/java/org/apache/maven/doxia/ConverterTest.java
index 5cfaf32..596190a 100644
--- a/src/test/java/org/apache/maven/doxia/ConverterTest.java
+++ b/src/test/java/org/apache/maven/doxia/ConverterTest.java
@@ -432,6 +432,16 @@ class ConverterTest extends InjectedTest {
assertEquals(DoxiaFormat.FML, autoDetectFormat("fml/test.fml"));
assertEquals(DoxiaFormat.XHTML, autoDetectFormat("xhtml/test.xhtml"));
+ assertEquals(DoxiaFormat.MARKDOWN,
autoDetectFormat("markdown/test.md"));
+ assertEquals(DoxiaFormat.MARKDOWN,
autoDetectFormat("markdown/test.markdown"));
+ }
+
+ @Test
+ void fileNamePatternsCoverEveryExtension() {
+ assertEquals(
+ "**/*.md,**/*.md.vm,**/*.markdown,**/*.markdown.vm",
+
DefaultConverter.getFileNamePatterns(DoxiaFormat.MARKDOWN.getExtensions(),
true));
+ assertEquals("**/*.apt",
DefaultConverter.getFileNamePatterns(DoxiaFormat.APT.getExtensions(), false));
}
@Test
diff --git a/src/test/resources/unit/markdown/test.markdown
b/src/test/resources/unit/markdown/test.markdown
new file mode 100644
index 0000000..563b465
--- /dev/null
+++ b/src/test/resources/unit/markdown/test.markdown
@@ -0,0 +1,3 @@
+# Test
+
+A paragraph.
diff --git a/src/test/resources/unit/markdown/test.md
b/src/test/resources/unit/markdown/test.md
new file mode 100644
index 0000000..563b465
--- /dev/null
+++ b/src/test/resources/unit/markdown/test.md
@@ -0,0 +1,3 @@
+# Test
+
+A paragraph.