GP-0: Styling HTML headings in converted Markdown files

This commit is contained in:
Ryan Kurtz 2025-04-07 12:22:47 -04:00
parent 768788c078
commit e8f539f622

View file

@ -57,6 +57,7 @@ public class MarkdownToHtml {
HtmlRenderer renderer = HtmlRenderer.builder() HtmlRenderer renderer = HtmlRenderer.builder()
.extensions(extensions) .extensions(extensions)
.attributeProviderFactory(new TableAttributeProvider()) .attributeProviderFactory(new TableAttributeProvider())
.attributeProviderFactory(new HeadingAttributeProvider())
.attributeProviderFactory(new CodeAttributeProvider()) .attributeProviderFactory(new CodeAttributeProvider())
.attributeProviderFactory(new LinkAttributeProvider()) .attributeProviderFactory(new LinkAttributeProvider())
.build(); .build();
@ -94,6 +95,25 @@ public class MarkdownToHtml {
} }
} }
/**
* Class to add custom style to headings
*/
private static class HeadingAttributeProvider
implements AttributeProvider, AttributeProviderFactory {
@Override
public AttributeProvider create(AttributeProviderContext attributeProviderContext) {
return new HeadingAttributeProvider();
}
@Override
public void setAttributes(Node node, String tagName, Map<String, String> attributes) {
if (node instanceof Heading heading && heading.getLevel() <= 2) {
attributes.put("style",
"border-bottom: solid 1px; border-bottom-color: #cccccc; padding-bottom: 8px;");
}
}
}
/** /**
* Class to add custom style to code tags and code blocks * Class to add custom style to code tags and code blocks
*/ */