Markdown to HTML Converter
Markdown to HTML Converter
AI Core module contains service ai.commonmark_converter for Markdown→HTML
conversion, backed by league/commonmark, so that callers get a single,
injectable CommonMarkConverter instance instead of each caller instantiating
its own with its own set of options.
New service & interface
Drupal\ai\Service\CommonMarkConverterFactoryInterface— singlefromOptions(array $options = []): CommonMarkConvertermethod that builds aLeague\CommonMark\CommonMarkConverterfrom options merged onto the module's defaults.Drupal\ai\Service\CommonMarkConverterFactory(default impl) — merges caller-supplied options ontoCommonMarkConverterFactoryInterface::DEFAULT_OPTIONS(html_inputset tostrip,allow_unsafe_linksset tofalse) and returns a configuredCommonMarkConverter.
Services
ai.commonmark_converter_factory(aliased toDrupal\ai\Service\CommonMarkConverterFactoryInterface) — the factory described above. Inject this when custom converter options are needed, and callfromOptions()to build a converter.ai.commonmark_converter(aliased toLeague\CommonMark\CommonMarkConverter) — a ready-to-useCommonMarkConverterbuilt from the factory's defaults, for the common case of converting Markdown to HTML without any custom options.
Example usage
// Convert with the default converter.
$html = \Drupal::service('ai.commonmark_converter')->convert($markdown)->getContent();
// Or build a converter with custom options via the factory.
$converter = \Drupal::service('ai.commonmark_converter_factory')
->fromOptions(['html_input' => 'allow']);
$html = $converter->convert($markdown)->getContent();