GP-0: Initial What's New update and some markdown-to-html link

improvements
This commit is contained in:
Ryan Kurtz
2025-01-09 14:18:56 -05:00
parent 0d3451c0c0
commit f5af708e91
5 changed files with 102 additions and 82 deletions

View File

@@ -87,10 +87,41 @@ public class MarkdownToHtml {
@Override
public void setAttributes(Node node, String tagName, Map<String, String> attributes) {
if (node instanceof Link) {
String href = attributes.get("href");
if (href != null && !href.startsWith("#") && href.toLowerCase().endsWith(".md")) {
attributes.put("href", href.substring(0, href.length() - 2) + "html");
}
fixupLinks(attributes);
}
}
private void fixupLinks(Map<String, String> attributes) {
String href = attributes.get("href");
// Ignore local anchor links
if (href == null || href.startsWith("#")) {
return;
}
// Ignore fully qualified URL's
if (href.toLowerCase().startsWith("http://") ||
href.toLowerCase().startsWith("https://")) {
return;
}
// Convert .md links to .html links
if (href.toLowerCase().endsWith(".md")) {
href = href.substring(0, href.length() - 2) + "html";
}
// Fixup known differences between repository link and release links
href = switch (href) {
case String s when s.contains("src/main/py") -> s.replace("src/main/py", "pypkg");
case String s when s.contains("src/main/java") -> null;
default -> href;
};
if (href != null) {
attributes.put("href", href);
}
else {
attributes.remove("href");
}
}
}