|
1 | 1 | # CommonMarkBundle |
2 | | -A Symfony 4+ bundle to easily configure league/commonmark |
| 2 | +A **Symfony 4 / 5** bundle to easily configure [league/commonmark](https://github.com/thephpleague/commonmark), |
| 3 | +allowing you to set multiple **MarkDown** converters. |
| 4 | + |
| 5 | + |
| 6 | +[](//packagist.org/packages/aymdev/commonmark-bundle) |
| 7 | +[](//packagist.org/packages/aymdev/commonmark-bundle) |
| 8 | + |
| 9 | +## Installation |
| 10 | +Simply install it with **Composer**, an auto-generated recipe will enable the bundle for you: |
| 11 | +```sh |
| 12 | +composer require aymdev/commonmark-bundle |
| 13 | +``` |
| 14 | + |
| 15 | +## Configuration |
| 16 | +No converter is created by default. |
| 17 | +Create a **YAML** configuration file at path `config/packages/aymdev_commonmark.yaml` with the following content: |
| 18 | +```yaml |
| 19 | +aymdev_commonmark: |
| 20 | + converters: |
| 21 | + # add any converter here |
| 22 | + my_custom_converter: |
| 23 | + type: 'github' |
| 24 | + options: |
| 25 | + enable_strong: true |
| 26 | + use_underscore: false |
| 27 | + |
| 28 | + my_other_converter: |
| 29 | + type: 'commonmark' |
| 30 | + extensions: |
| 31 | + - League\CommonMark\Extension\HeadingPermalink\HeadingPermalinkExtension |
| 32 | +``` |
| 33 | +
|
| 34 | +### Converter settings |
| 35 | +
|
| 36 | +>Note that all keys inside a converter are optional. |
| 37 | +
|
| 38 | +#### Converter type |
| 39 | +
|
| 40 | +The `type` key can be used to choose between a *CommonMark* or a *GitHub* converter: |
| 41 | + |
| 42 | + - `commonmark` (default): `CommonMarkConverter` |
| 43 | + - `github`: `GithubFlavoredMarkdownConverter` |
| 44 | + |
| 45 | +#### Converter options |
| 46 | + |
| 47 | +The `options` key holds the configuration passed to the converter, as an array. |
| 48 | +>For more information, see the [CommonMark documentation about Configuration](https://commonmark.thephpleague.com/1.5/configuration/). |
| 49 | + |
| 50 | +#### Converter extensions |
| 51 | + |
| 52 | +The `extensions` key allows to add any extension class to a converter. |
| 53 | +>Check the complete list of extensions on the [CommonMark documentation](https://commonmark.thephpleague.com/1.5/extensions/overview/). |
| 54 | + |
| 55 | +### Using the converters |
| 56 | + |
| 57 | +The bundle registers your converters as **services** with the following ID: |
| 58 | +``` |
| 59 | +aymdev_commonmark.converter.CONVERTER_NAME |
| 60 | +``` |
| 61 | + |
| 62 | +It also creates an alias, so you can get them by *autowiring* using the *converter name* as the *argument name*, |
| 63 | +type with the `League\CommonMark\CommonMarkConverter` class. |
| 64 | + |
| 65 | +**Example YAML configuration**: |
| 66 | +```yaml |
| 67 | +aymdev_commonmark: |
| 68 | + converters: |
| 69 | + # You can add an argument for this converter as: |
| 70 | + # CommonMarkConverter $myConverter |
| 71 | + my_converter: |
| 72 | +``` |
0 commit comments