# commonmark-spring-starter **Repository Path**: jiangtj/commonmark-spring-starter ## Basic Information - **Project Name**: commonmark-spring-starter - **Description**: A spring starter wapper for commonmark - **Primary Language**: Java - **License**: Apache-2.0 - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2022-03-15 - **Last Updated**: 2023-03-06 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # Commonmark Spring Starter A spring boot starter wapper for commonmark ## Install 1/2: Add this to pom.xml: ```xml com.jiangtj.common commonmark-spring-starter ${last-version} ``` 2/2: Configuring github packages [configuring-apache-maven-for-use-with-github-packages](https://docs.github.com/en/packages/guides/configuring-apache-maven-for-use-with-github-packages) ## Usage We provide Parser and HtmlRenderer instance, you can easily inject ```java @Resource private Parser parser; @Resource private HtmlRenderer renderer; Node document = parser.parse("This is *Sparta*"); renderer.render(document); ``` Normally, we don't care about the middle process, so you can use CommonMark simplified ```java @Resource private CommonMark commonMark; commonMark.render(document); // == parser.parse() and renderer.render() ``` ## Custom Here are some default configurations for the HtmlRenderer, which you can override in the configuration file if needed. ```properties commonmark.softbreak=\\n commonmark.escapeHtml=false commonmark.sanitizeUrls=false commonmark.percentEncodeUrls=false ``` If there is an instance of AttributeProviderFactory or HtmlNodeRendererFactory, it will be automatically configured ```java @Configuration class AttributeBean { @Bean public AttributeProviderFactory imageAttributeProvider() { return context -> new AttributeProviderTests.ImageAttributeProvider(); } } class ImageAttributeProvider implements AttributeProvider { @Override public void setAttributes(Node node, String tagName, Map attributes) { if (node instanceof Image) { attributes.put("class", "border"); } } } ``` Extension is the same, only need to provide an extended instance. ```xml org.commonmark commonmark-ext-task-list-items 0.18.2 ``` ```java @Configuration public static class ExtensionBeans { @Bean public Extension taskListItemsExtension() { return TaskListItemsExtension.create(); } } ``` You can see how to use it in [the test case](https://github.com/jiangtj-lab/commonmark-spring-starter/tree/master/src/test/java/com/jiangtj/common/commonmarkspringstarter)