Home

Awesome

commonmark-ext-notifications

Maven Central status Java CI with Maven

This is a plugin for commonmark-java that allows to create notifications paragraphs in markdown like the following (taken from Isabel Castillo blog)

image

using a very simple syntax

! This is an info message.
!v This is a success message.
!! Consider this a warning.
!x This is an error message.

Usage

Simply add the extension to the Parser & Renderer objects.

Extension notificationExtension = NotificationsExtension.create();

Parser parser = Parser
		.builder()
		.extensions(Collections.singleton(notificationExtension))
		.build();

Node document = parser.parse("! Use Notifications Extension !!!");

HtmlRenderer renderer = HtmlRenderer
		.builder()
		.extensions(Collections.singleton(notificationExtension))
		.build();
renderer.render(document);
/*
	<div class="notification_info">
	<p>Use Notifications Extension !!!</p>
	</div>
 */

Configuration

If you want specific rendering to adapt to an existing CSS framework you can define which HTML node will be rendered (see NotificationsExtension.withDomElementMapper) or which CSS classes (see NotificationsExtension.withClassMapper) will be applied.

For exemple to render Boostrap Alerts, you could use:

Extension notificationExtension = NotificationsExtension.create()
        .withClassMapper(n -> n == Notification.ERROR ? "alert alert-danger" : "alert alert-" + n.name().toLowerCase());

Parser parser = Parser
		.builder()
		.extensions(Collections.singleton(notificationExtension))
		.build();

Node document = parser.parse("! Use Notifications Extension !!!");

HtmlRenderer renderer = HtmlRenderer
		.builder()
		.extensions(Collections.singleton(notificationExtension))
		.build();
renderer.render(document);
/*
	<div class="alert alert-info">
	<p>Use Notifications Extension !!!</p>
	</div>
 */

Maven coordinates

You will find the latest version of the extension in maven central.

<dependency>
    <groupId>fr.brouillard.oss</groupId>
    <artifactId>commonmark-ext-notifications</artifactId>
    <version>1.1.0</version>
</dependency>    

Build & release

Normal build

Release