Hello,
I can think of two ways of solving this:
- Use child selectors for CSS
- Implement a CommonMark extension.
My answer focuses on the second approach.
this is quite a common question. Laravel uses the CommonMark library for this: https://github.com/laravel/framework/blob/443ec4438c48923c9caa9c2b409a12b84a10033f/src/Illuminate/Support/Str.php#L619-L624
The CommonMark library can be extended. In the following, you'll find a link to an issue with code on how to add the class attribute to specific elements. Unfortunately, as far as I know, you cannot register CommonMark extensions globally. So if you want to use Str#markdown-Method, you're out of luck. But you can compose your own CommonMark environment in, for example, a custom helper method. It's fairly easy to do. Here is the example for such a class:
https://github.com/GrahamCampbell/Laravel-Markdown/issues/155
This is the class Laravel uses: https://github.com/thephpleague/commonmark/blob/e11438aa1ed14505ee84c0e736378b5d6781b3c7/src/GithubFlavoredMarkdownConverter.php#L23
Here's some documentation about extensions: https://commonmark.thephpleague.com/2.4/customization/extensions/