GP-5496: Converting headless readme to markdown

This commit is contained in:
Ryan Kurtz 2025-02-28 16:33:35 -05:00
parent 6d44b9bad7
commit 95060a2dd8
6 changed files with 1084 additions and 1448 deletions

View file

@ -21,4 +21,5 @@ dependencies {
implementation 'org.commonmark:commonmark:0.23.0'
implementation 'org.commonmark:commonmark-ext-heading-anchor:0.23.0'
implementation 'org.commonmark:commonmark-ext-footnotes:0.23.0'
implementation 'org.commonmark:commonmark-ext-gfm-tables:0.23.0'
}

View file

@ -21,6 +21,7 @@ import java.util.Map;
import org.commonmark.Extension;
import org.commonmark.ext.footnotes.FootnotesExtension;
import org.commonmark.ext.gfm.tables.*;
import org.commonmark.ext.heading.anchor.HeadingAnchorExtension;
import org.commonmark.node.Link;
import org.commonmark.node.Node;
@ -51,11 +52,12 @@ public class MarkdownToHtml {
}
// Setup the CommonMark Library with the needed extension libraries
List<Extension> extensions =
List.of(HeadingAnchorExtension.create(), FootnotesExtension.create());
List<Extension> extensions = List.of(HeadingAnchorExtension.create(),
FootnotesExtension.create(), TablesExtension.create());
Parser parser = Parser.builder().extensions(extensions).build();
HtmlRenderer renderer = HtmlRenderer.builder()
.extensions(extensions)
.attributeProviderFactory(new TableAttributeProvider())
.attributeProviderFactory(new LinkAttributeProvider())
.build();
@ -73,6 +75,25 @@ public class MarkdownToHtml {
}
}
/**
* Class to add custom style to tables
*/
private static class TableAttributeProvider
implements AttributeProvider, AttributeProviderFactory {
@Override
public AttributeProvider create(AttributeProviderContext attributeProviderContext) {
return new TableAttributeProvider();
}
@Override
public void setAttributes(Node node, String tagName, Map<String, String> attributes) {
if (node instanceof TableBlock || node instanceof TableCell) {
attributes.put("style",
"border: 1px solid black; border-collapse: collapse; padding: 5px;");
}
}
}
/**
* Class to help adjust links to Markdown files to instead become links to HTML files
*/