Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FR: Extensible Markdown Parser #1173

Closed
austenc opened this issue Dec 31, 2019 · 3 comments · Fixed by #1181
Closed

FR: Extensible Markdown Parser #1173

austenc opened this issue Dec 31, 2019 · 3 comments · Fixed by #1181

Comments

@austenc
Copy link

austenc commented Dec 31, 2019

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!

@jasonvarga
Copy link
Member

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

@jasonvarga jasonvarga transferred this issue from statamic/ideas Jan 6, 2020
@jasonvarga
Copy link
Member

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

See laravel/framework#30982 and laravel/framework#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()

@jasonvarga
Copy link
Member

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants