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

Add components mapping. #74

Closed
minhnbnt opened this issue Jun 13, 2024 · 1 comment · Fixed by #100
Closed

Add components mapping. #74

minhnbnt opened this issue Jun 13, 2024 · 1 comment · Fixed by #100
Labels
enhancement New feature or request released

Comments

@minhnbnt
Copy link

Is there an easy way to convert components to other like renderers in svelte-markdown or react-markdown.

I want to add a copy button in pre blocks but writing unified plugins seems too hard for me.

@BearToCode
Copy link
Owner

BearToCode commented Jun 13, 2024

Hi, I checked out svelte-markdown and it looks really cool. It would be great to have something like that here, since it is often requested and would make rendering components easier.

Here are some ideas for the implementation, for future me or anyone who might want to start working on this :)

  • Apply a final transform to the HTML syntax tree;
  • The transform should take every element in the tree and test if it match a certain criteria;
  • If it match one, it is passed as property of a corresponding component(💡make it framework agnostic, so that it can be used in other frameworks Lib Version for native html #37);
    • In Svelte: render the component server-side(using Component.render) and client-side, adding children to the component if necessary; on the client, replace the static elements with the actual components(maybe save a ref to an id on the elements, which are query-selected and replaced with the corresponding component);
  • Convert the generated HTML back into the a syntax tree and put it back where it originally was.

It would be cool to make it into a dedicated plugin, but weird things might happen if this plugin's transformer is not run last.

@BearToCode BearToCode added the enhancement New feature or request label Jun 13, 2024
Repository owner deleted a comment from github-actions bot Jul 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request released
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants