Cms: FR: Extensible Markdown Parser

Created on 31 Dec 2019  路  3Comments  路  Source: statamic/cms

Would love to see the markdown parser become more extensible. Seems like this would just be a matter of adding an "alias class" on top of ParsedownExtra. Then we could use the service container to bind / alias a class which extends the markdown parser. Perhaps it could be called MarkdownParser and live in the statamic namespaces? This class would extend ParsedownExtra (which has no namespace).

This would allow for v3 users and addon developers to easily build markdown extensions. For example, let's say you wanted to have a special content block for hot tips. 馃敟 The markdown would look like this:

:::tip
Some amazing tip text
:::

Currently ParsedownExtra is used in the Markdown fieldtype and in the Statamic\Support\Html class.

I just tried to use the service container to bind my own implementation of ParsedownExtra.... but this becomes problematic because that (vendor) class has no namespace. So once you overwrite the root namespace entry for it, you can't extend the base class.

If this sounds like an acceptable FR, I'd be happy to make a PR to the proper v3 repository.

Thank you!

Most helpful comment

Actually, I've just noticed that Laravel now requires league/commonmark instead of Parsedown.

See https://github.com/laravel/framework/pull/30982 and https://github.com/laravel/framework/pull/30973

The league/commonmark library allows custom extensions to be created.
https://commonmark.thephpleague.com/1.0/customization/overview/

I think I would want to change to commonmark, and then allow developers to add extensions, which would be used by Statamic\Support\Html::markdown()

All 3 comments

I've been wanting to do this. Good idea.

Actually, I've just noticed that Laravel now requires league/commonmark instead of Parsedown.

See https://github.com/laravel/framework/pull/30982 and https://github.com/laravel/framework/pull/30973

The league/commonmark library allows custom extensions to be created.
https://commonmark.thephpleague.com/1.0/customization/overview/

I think I would want to change to commonmark, and then allow developers to add extensions, which would be used by Statamic\Support\Html::markdown()

If we switch to commonmark, need to make sure these work:

Was this page helpful?
0 / 5 - 0 ratings

Related issues

sauerbraten picture sauerbraten  路  3Comments

dakisan picture dakisan  路  4Comments

aerni picture aerni  路  3Comments

filipac picture filipac  路  4Comments

jcohlmeyer picture jcohlmeyer  路  4Comments