lumeland / experimental-plugins

A repo to test and experiment with plugins for Lume
13 stars 9 forks source link

Added Remark plugin #5

Closed naiyerasif closed 2 years ago

naiyerasif commented 2 years ago

This change adds a Remark plugin to process markdown with Remark and generate the subsequent HTML with Rehype.

I have used esm.sh as the import host because that's what most of the Remark and Rehype ecosystem prefers.

oscarotero commented 2 years ago

Thanks, @naiyerasif I'm wondering if we can create two different plugins, one for remark and other for rehype. In this way, users could use rehype plugins with any html, not only those generenated from markdown (for example, to process html from nunjucks, jsx, etc).

naiyerasif commented 2 years ago

@oscarotero Remark and Rehype can indeed be used as standalone processors. I'll explore how best this can be done.

naiyerasif commented 2 years ago

I have done some changes:

oscarotero commented 2 years ago

Hi, that looks pretty good!

I have a couple of comments, let me know your opinion:

naiyerasif commented 2 years ago

Hey Oscar,

Thoughts?

oscarotero commented 2 years ago

Ok, in that case it's needed to register it as async filter adding true to the third argument:

site.filter("mdAsync", asyncFn, true);

btw: is there any way to detect if async filter is needed? I'm thinking in register only one the md filter but set it sync or async depending on the plugins used (or maybe adding an option to the plugin configuration).

naiyerasif commented 2 years ago

I have done the suggested changes (removing preset support and renaming md and mdSync filters to mdAsync and md respectively.

btw: is there any way to detect if async filter is needed? I'm thinking in register only one the md filter but set it sync or async depending on the plugins used (or maybe adding an option to the plugin configuration).

Unfortunately, the current Processor and Plugin API does not surface this information so it cannot be done without some ugly hack.

naiyerasif commented 2 years ago

One another thing about this plugin: it does not generate safe HTML. This is by intent so that people can inject raw HTML and MDX. Would it make sense to introduce an option to generate sanitized HTML?

oscarotero commented 2 years ago

Yeah, I think it's fine to allow raw HTML by default and add an option to disable it.

naiyerasif commented 2 years ago

Done. A sanitize flag will let users switch on HTML sanitization. I'll have to add a note about this in the docs reminding that this might affect MDX and any other plugin that generates raw HTML.

oscarotero commented 2 years ago

Ok, It looks good to me. Can I merge it?

naiyerasif commented 2 years ago

Sure. I'll work on some docs when you think this can be promoted to main repo.