Ability to blacklist or whitelist certain parsers. #648
-
Description This would be useful if you want a more control over how content is rendered in your site. Example use cases: Disabling embedded images and thematic breaks in comments, or only allowing bold, italics, and underlines. |
Beta Was this translation helpful? Give feedback.
Replies: 5 comments
-
This is already supported. :) |
Beta Was this translation helpful? Give feedback.
-
Is it anywhere in the docs? I can't seem to find it. |
Beta Was this translation helpful? Give feedback.
-
The general gist is that you create your own custom extension which only registers the parsers, renderers, etc. for the features you want to support. Here's the Here's the You can use one of those as-is or create your own version to fit your own needs. I definitely agree that the documentation could be better - PRs would be welcome! 😉 |
Beta Was this translation helpful? Give feedback.
-
Oh, one important note - extensions can only add features, not remove them, so don't use use League\CommonMark\CommonMarkConverter;
use League\CommonMark\Environment;
-$environment = Environment::createCommonMarkEnvironment();
+$environment = new Environment();
+$environment->addExtension(new MyAwesomeCustomExtension());
$converter = new CommonMarkConverter([], $environment);
echo $converter->convertToHtml('Hello world!'); |
Beta Was this translation helpful? Give feedback.
-
Thank you, managed to get it working! |
Beta Was this translation helpful? Give feedback.
The general gist is that you create your own custom extension which only registers the parsers, renderers, etc. for the features you want to support.
Here's the
CommonMarkCoreExtension
which includes almost everything: https://github.com/thephpleague/commonmark/blob/master/src/Extension/CommonMarkCoreExtension.phpHere's the
InlinesOnly
extension which only includes things you'd typically find in one-line comments: https://github.com/thephpleague/commonmark/blob/master/src/Extension/InlinesOnly/InlinesOnlyExtension.phpYou can use one of those as-is or create your own version to fit your own needs.
I definitely agree that the documentation could be better - PRs would be welcome! 😉