Interface MarkdownRenderer
- All Known Implementing Classes:
CommonmarkMarkdownRenderer
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:
The rendered HTML is intended to be dropped inside a 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 TypeMethodDescriptionstatic MarkdownRendererresolve()Resolves the active renderer: the firstServiceLoader-registered provider if one exists, otherwise the built-in commonmark-java default.static MarkdownRendererresolve(Iterable<MarkdownRenderer> providers) Resolution seam used byresolve(), exposed package-private so both the provider-found and default-fallback branches can be exercised without touching the JVM-wideServiceLoaderregistry.Renders the specified markdown source to an HTML fragment.
-
Method Details
-
toHtml
Renders the specified markdown source to an HTML fragment.- Parameters:
markdown- The markdown source. Must not benull (an empty string renders to an empty fragment).- Returns:
- The rendered HTML fragment.
- Throws:
IllegalArgumentException- Ifmarkdown isnull .
-
resolve
Resolves the active renderer: the firstServiceLoader-registered provider if one exists, otherwise the built-in commonmark-java default.- Returns:
- The active renderer. Never
null .
-
resolve
Resolution seam used byresolve(), exposed package-private so both the provider-found and default-fallback branches can be exercised without touching the JVM-wideServiceLoaderregistry.- Parameters:
providers- The candidate providers (a liveServiceLoaderin production).- Returns:
- The first provider if any, otherwise a new
CommonmarkMarkdownRenderer.
-