Skip to content

feat: add support for plugins#58

Closed
szymonograbek wants to merge 3 commits intoimwithye:mainfrom
szymonograbek:feat/plugins
Closed

feat: add support for plugins#58
szymonograbek wants to merge 3 commits intoimwithye:mainfrom
szymonograbek:feat/plugins

Conversation

@szymonograbek
Copy link
Copy Markdown
Contributor

@szymonograbek szymonograbek commented Oct 15, 2025

📝 Description

This PR adds support to pass plugins to the processor, so we can use i.e. rehypeParse and rehypeRemark to parse HTML to markdown. I've added temporal samples as typescript files to test this locally, if this PR will be accepted then I'll move them to the rest of markdown files.

📌 Related Issue

Link: #43

📷 Screenshots

Parsed HTML:
Simulator Screenshot - iPhone 17 Pro - 2025-10-15 at 08 02 41

✅ Checklist

  • My PR title follows the Conventional Commit format (e.g. feat:, fix:, chore:)
  • This PR addresses the related issue (if applicable)
  • I have attached a sample Markdown file (.md) used for testing
  • I have attached at least one screenshot of the rendered output (light and/or dark mode preferred)
  • I have run pnpm run lint:fix to fix formatting and lint errors
  • I have tested the changes in the example app (pnpm i && cd example && pnpm i && pnpm run ios)

@imwithye
Copy link
Copy Markdown
Owner

@szymonograbek Thank you! I will take a look these days.

Copy link
Copy Markdown
Collaborator

@LouisDvr LouisDvr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm excited by the support for plugins so I had a look at that part of the PR to try and fasten its inclusion in the lib. Thanks for doing it!

As I commented, I think considering remark-parse like an optional plugin leads to problems so I would recommend forcing its usage

Also, this comment in the original issue even recommends to drop suggested plugins and let users use whichever plugin they need. It could reduce the bundle size to avoid importing remark-gfm in all cases but I wonder if it wouldn't be misleading to say the lib support GFM (because it includes the appropriate renderers) while still requiring users to pass the plugin manually. Wdyt @szymonograbek and @imwithye ?

Finally, I think adding a mermaid example isn't really linked to adding support for custom plugins, though originating from the same discussion, so it would be cleaner to put it in a separate PR to avoid bloating this one and ease the review and acceptance or not of each subject (mermaid example represents more than 98% of the changed lines)

Comment thread src/markdown.tsx
}: MarkdownProps) => {
const tree = useMemo(() => parser.parse(markdown), [markdown]);
const processor = useMemo(() => {
return unified().use(remarkPlugins);
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And here

Suggested change
return unified().use(remarkPlugins);
return unified().use(remarkParse).use(remarkPlugins);

Comment thread src/markdown.tsx
import { Styles, mergeStyles } from "./themes/themes";

const parser = unified().use(remarkParse).use(remarkGfm);
const defaultRemarkPlugins: PluggableList = [remarkParse, remarkGfm];
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think remarkParse shouldn't be included in the default plugins and the lib should rather use it by default because

  1. users can pass an empty array, which would lead to a runtime error (TypeError: Cannot "processSync" without "Parser")
  2. remarkParse is the official remark parser so users will always want to use it when customizing the plugins list so using it by default would reduce the boilerplate

This would give

Suggested change
const defaultRemarkPlugins: PluggableList = [remarkParse, remarkGfm];
const defaultRemarkPlugins: PluggableList = [remarkGfm];

Comment thread src/index.tsx Outdated
@szymonograbek szymonograbek changed the title feat: add support for plugins, add mermaid example feat: add support for plugins Oct 15, 2025
@szymonograbek
Copy link
Copy Markdown
Contributor Author

As I commented, I think considering remark-parse like an optional plugin leads to problems so I would recommend forcing its usage

Also, this comment in the original issue even recommends to drop suggested plugins and let users use whichever plugin they need. It could reduce the bundle size to avoid importing remark-gfm in all cases but I wonder if it wouldn't be misleading to say the lib support GFM (because it includes the appropriate renderers) while still requiring users to pass the plugin manually. Wdyt @szymonograbek and @imwithye ?

I've though about it and I agree, we should keep remark-parse as a non-optional. This would follow how react-markdown works. I'm not sure what to do with remark-gfm - I think we should do as you say and mention that the library supports GFM, but to parse it developers should install and add the plugin. I'll leave the decision to the library owner.

Finally, I think adding a mermaid example isn't really linked to adding support for custom plugins, though originating from the same discussion, so it would be cleaner to put it in a separate PR to avoid bloating this one and ease the review and acceptance or not of each subject (mermaid example represents more than 98% of the changed lines)

Sure, I've removed it from this PR

@imwithye
Copy link
Copy Markdown
Owner

Thank you for your PR! I will review it this week. Overall, it looks good to me!

@LouisDvr
Copy link
Copy Markdown
Collaborator

Hey @imwithye, I hope you're doing well. Did you have time to have a look to this PR?

It would really help using this lib for a lot of use-cases which require patching it for the moment. If you need anything to speed things up, I'd be happy to provide you with any assistance I can.

Thanks again for this awesome lib!

@LouisDvr
Copy link
Copy Markdown
Collaborator

Hey @szymonograbek, I hope you're doing well!

I reached to @imwithye regarding the maintenance of this repo. He doesn't currently have enough time for it but added me as collaborator on this repo so I can help by reviewing and merging PRs. Do you wish to finish the work you've started on this PR?

If so, I think you can do what we've talked about regarding remarkParse (remove it from the default plugins and use it directly when defining the processor). You'll then need to update your example since it won't work anymore.

Regarding remark-gfm, I think we can keep it for now since we were hesitating and it would be a breaking change.

Btw, having a look to the code to remember what was done here, I've noticed you disabled the react/prop-types ESLint rule but I don't see what the problem with it was. Was it something you forgot to remove or was there a reason I don't see?

I'd understand you don't have time anymore for this and will happily do the last changes if you don't want to do them or don't answer in the next few weeks

Have a nice day!

@szymonograbek
Copy link
Copy Markdown
Contributor Author

szymonograbek commented Feb 15, 2026

@LouisDvr TBH I don't have much free time to finish this and I no longer work in the project that needed this change, so feel free to take it over

@LouisDvr
Copy link
Copy Markdown
Collaborator

@LouisDvr TBH I don't have much free time to finish this and I no longer work in the project that needed this change, so feel free to take it over

No problem! I'll apply the last changes

Thank you very much for the work you've put in this contribution 🙏🏼

@LouisDvr LouisDvr mentioned this pull request Feb 22, 2026
6 tasks
@LouisDvr
Copy link
Copy Markdown
Collaborator

Closing since work has been continued in PR #60

@LouisDvr LouisDvr closed this Feb 22, 2026
LouisDvr added a commit that referenced this pull request Mar 5, 2026
## 📝 Description

This PR adds support for remark plugins to allow users take advantage of
the remark ecosystem and extend the lib's behavior (when using plugins
that add new nodes, users will have to inject the needed renderers using
the `customRenderers` prop). It finishes the work started in PR #58 by
[szymonograbek](https://github.com/szymonograbek). It also adds a
section in the `README` file to explain how to use plugins with the lib.

## 📌 Related Issue (Optional)

Link: #43 

## 📷 Screenshots (Optional)

Example using the `remark-cjk-friendly` plugin.
| Before | After |
| ------ | ------ |
| <img height="550"
src="https://github.com/user-attachments/assets/fcb98d17-7065-4c4e-a369-a593c381c439"
/> | <img height="550"
src="https://github.com/user-attachments/assets/45dfbd55-ef12-41fb-afba-c7d85c9a3f4f"
/> |

## 📄 Test Markdown File (Optional)

File `05_cjk_plugin_example.md` included in the PR

## ✅ Checklist

- [x] My PR title follows the Conventional Commit format (e.g. `feat:`,
`fix:`, `chore:`)
- [x] This PR addresses the related issue (if applicable)
- [x] I have attached a sample Markdown file (`.md`) used for testing
- [x] I have attached at least one screenshot of the rendered output
(light and/or dark mode preferred)
- [x] I have run `pnpm run lint:fix` to fix formatting and lint errors
- [x] I have tested the changes in the example app (`pnpm i && cd
example && pnpm i && pnpm run ios`)

---------

Co-authored-by: Szymon Ograbek <szymon.ograbek2@gmail.com>
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 this pull request may close these issues.

3 participants