Interface MarkdownRenderer

All Known Implementing Classes:
CommonmarkMarkdownRenderer

public interface MarkdownRenderer
A pluggable markdown-to-HTML renderer: hand it a markdown string, get back an HTML fragment.

This is the extension point of the optional markdown module — the toolkit's answer to "the way ViewDef turns a list of beans into a themed table, hand me a markdown string and give me back HTML". The interface is deliberately library-neutral: a single toHtml(String) method, so any parser can sit behind it. The shipped default is CommonmarkMarkdownRenderer (commonmark-java with the GFM tables extension enabled), but a consumer can swap in their own parser without the toolkit knowing which library won.

Selecting an implementation:

resolve() returns the active renderer via the standard ServiceLoader SPI mechanism: if a consumer registers their own provider (a META-INF/services/ org.apache.juneau.console.views.markdown.MarkdownRenderer file naming their implementation class), that provider wins; otherwise the built-in commonmark-java default is used. The default is intentionally not registered as a service, so a single consumer-supplied provider is always unambiguous.

Example:

// Render markdown to an HTML fragment using whichever renderer is active. MarkdownRenderer renderer = MarkdownRenderer.resolve(); String html = renderer.toHtml("# Runbook\n\nStep one.");

The rendered HTML is intended to be dropped inside a .jc-prose container so it picks up the console's prose typography. Raw HTML in the source is escaped; javascript: / data: URLs are stripped. The row-detail runtime still allowlist-copies the fragment (never innerHTML) when FieldFormat.MARKDOWN is set.

See Also:
Since:
10.0.0
  • Method Summary

    Modifier and Type
    Method
    Description
    Resolves the active renderer: the first ServiceLoader-registered provider if one exists, otherwise the built-in commonmark-java default.
    Resolution seam used by resolve(), exposed package-private so both the provider-found and default-fallback branches can be exercised without touching the JVM-wide ServiceLoader registry.
    toHtml(String markdown)
    Renders the specified markdown source to an HTML fragment.
  • Method Details

    • toHtml

      String toHtml(String markdown)
      Renders the specified markdown source to an HTML fragment.
      Parameters:
      markdown - The markdown source. Must not be null (an empty string renders to an empty fragment).
      Returns:
      The rendered HTML fragment.
      Throws:
      IllegalArgumentException - If markdown is null.
    • resolve

      Resolves the active renderer: the first ServiceLoader-registered provider if one exists, otherwise the built-in commonmark-java default.
      Returns:
      The active renderer. Never null.
    • resolve

      Resolution seam used by resolve(), exposed package-private so both the provider-found and default-fallback branches can be exercised without touching the JVM-wide ServiceLoader registry.
      Parameters:
      providers - The candidate providers (a live ServiceLoader in production).
      Returns:
      The first provider if any, otherwise a new CommonmarkMarkdownRenderer.