Extension 03 / kotmark-ext-gfm-alerts
GFM alerts
Alerts parse as block quotes and use the alert renderer when the extension is enabled.
- Artifact
- io.heapy.kotmark:kotmark-ext-gfm-alerts:0.1.0
- Package
- io.heapy.kotmark.ext.gfm.alerts
Usage
The built-in alert types are NOTE, TIP, IMPORTANT, WARNING, and CAUTION; applications can register additional names.
Add a custom alert type
import io.heapy.kotmark.ext.gfm.alerts.alerts
import io.heapy.kotmark.extensions
import io.heapy.kotmark.parser.parser
import io.heapy.kotmark.renderer.html.htmlRenderer
fun renderWithAlerts(markdown: String): String {
val extensions = extensions {
alerts {
// NOTE, TIP, IMPORTANT, WARNING, and CAUTION are allowed by default.
addCustomType("INFO", "Information")
}
}
val document = parser { extensions(extensions) }.parse(markdown)
return htmlRenderer { extensions(extensions) }.render(document)
}Example
INPUT · Markdown
> [!INFO]
> Extensions are opt-in.
> [!WARNING]
> Register them on both sides.OUTPUT · HTML
<div class="markdown-alert markdown-alert-info" data-alert-type="info">
<p class="markdown-alert-title">Information</p>
<p>Extensions are opt-in.</p>
</div>
<div class="markdown-alert markdown-alert-warning" data-alert-type="warning">
<p class="markdown-alert-title">Warning</p>
<p>Register them on both sides.</p>
</div>Behavior
Alert blocks preserve their block-quote content. Custom types are registered with a display title and receive the corresponding markdown-alert-* class in HTML.