This is the documentation for the unsupported version 1.6. Please consider upgrading your code to the latest stable version

Configuration

Many aspects of this library’s behavior can be tweaked using configuration options.

You can provide an array of configuration options to the CommonMarkConverter when creating it:

$config = [
    'renderer' => [
        'block_separator' => "\n",
        'inner_separator' => "\n",
        'soft_break'      => "\n",
    ],
    'commonmark' => [
        'enable_em' => true,
        'enable_strong' => true,
        'use_asterisk' => true,
        'use_underscore' => true,
        'unordered_list_markers' => ['-', '*', '+'],
    ],
    'html_input' => 'escape',
    'allow_unsafe_links' => false,
    'max_nesting_level' => PHP_INT_MAX,
];

If you’re using the basic CommonMarkConverter or GithubFlavoredMarkdown classes, simply pass the configuration array into the constructor:

use League\CommonMark\CommonMarkConverter;
use League\CommonMark\GithubFlavoredMarkdownConverter;

$converter = new CommonMarkConverter($config);
// or
$converter = new GithubFlavoredMarkdownConverter($config);

Otherwise, if you’re using MarkdownConverter to customize the extensions in your parser, pass the configuration into the Environment’s mergeConfig() method instead:

use League\CommonMark\Environment;
use League\CommonMark\Extension\InlinesOnly\InlinesOnlyExtension;
use League\CommonMark\MarkdownConverter;

$environment = new Environment();

// TODO: Add any/all the extensions you wish; for example:
$environment->addExtension(new InlinesOnlyExtension());

// Here's where we set the configuration array:
$environment->mergeConfig($config);

// Go forth and convert you some Markdown!
$converter = new MarkdownConverter($environment);

Here’s a list of currently-supported options:

Additional configuration options are available for some of the available extensions - refer to their individual documentation for more details.

Environment

The configuration is ultimately passed to (and managed via) the Environment. If you’re creating your own Environment, simply pass your config array into its constructor instead.

The Environment also exposes two methods for managing the configuration:

Learn more about customizing the Environment


Edit this page