mirror of
https://github.com/NationalSecurityAgency/ghidra.git
synced 2026-05-27 20:00:29 +08:00
GP-0: Styling HTML code blocks in converted Markdown files
This commit is contained in:
@@ -23,8 +23,7 @@ import org.commonmark.Extension;
|
|||||||
import org.commonmark.ext.footnotes.FootnotesExtension;
|
import org.commonmark.ext.footnotes.FootnotesExtension;
|
||||||
import org.commonmark.ext.gfm.tables.*;
|
import org.commonmark.ext.gfm.tables.*;
|
||||||
import org.commonmark.ext.heading.anchor.HeadingAnchorExtension;
|
import org.commonmark.ext.heading.anchor.HeadingAnchorExtension;
|
||||||
import org.commonmark.node.Link;
|
import org.commonmark.node.*;
|
||||||
import org.commonmark.node.Node;
|
|
||||||
import org.commonmark.parser.Parser;
|
import org.commonmark.parser.Parser;
|
||||||
import org.commonmark.renderer.html.*;
|
import org.commonmark.renderer.html.*;
|
||||||
|
|
||||||
@@ -58,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 CodeAttributeProvider())
|
||||||
.attributeProviderFactory(new LinkAttributeProvider())
|
.attributeProviderFactory(new LinkAttributeProvider())
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
@@ -94,6 +94,26 @@ public class MarkdownToHtml {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class to add custom style to code tags and code blocks
|
||||||
|
*/
|
||||||
|
private static class CodeAttributeProvider
|
||||||
|
implements AttributeProvider, AttributeProviderFactory {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public AttributeProvider create(AttributeProviderContext attributeProviderContext) {
|
||||||
|
return new CodeAttributeProvider();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setAttributes(Node node, String tagName, Map<String, String> attributes) {
|
||||||
|
if (node instanceof Code || node instanceof IndentedCodeBlock ||
|
||||||
|
node instanceof FencedCodeBlock) {
|
||||||
|
attributes.put("style", "background-color: #eef;");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class to help adjust links to Markdown files to instead become links to HTML files
|
* Class to help adjust links to Markdown files to instead become links to HTML files
|
||||||
*/
|
*/
|
||||||
|
|||||||
Reference in New Issue
Block a user