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

Issue with dynamic updates like changing theme and rendering content via streaming #80

Open
jaydeep987 opened this issue Jun 18, 2024 · 1 comment

Comments

@jaydeep987
Copy link

jaydeep987 commented Jun 18, 2024

Initially I loved this library, seeing seamless integration of plugins.
But as i went to use it for advanced use cases, I felt disappointed.

First thing, I cannot change theme of code highlighter without re-initializing carta. So even following does not work:

carta.highlighter().then(async (h) => {
  h.setTheme(currentTheme);
});

I must have to re-init carta = new Carta({theme: currentTheme});

Second thing, live streaming of markdown is not supported directly only for Mardown viewer. I tried to copy internal Renderer component, it works but then especially with code and tikz there are limitations. It will throw errors like "javascript language not found, please load it first". May be this is due to smallest debounce time I set. but debounce time is still not valid solution, if library is trying to load language file from server as needed. what if request takes lot of time? Also debounce time makes streaming flow slower.
So i need to load all bundled languages at once, which is also not good practice, as why I load python when I actually do not need it.
Note that I cannot render html from server side. Server already returns markdown as EventStream. Think like I want to make chat bot.

Ultimately either there is no better way for such use case in this lib OR I am not getting right way from docs. I would appreciate if developers of this lib can throw some light and give me little help.

Thanks,
Jay

@BearToCode
Copy link
Owner

  1. What theme are you trying to change at runtime? Is it the one used to highlight Markdown in the code editor or the one for the output HTML with plugin-code? In the first case, your example should work (as long as the theme is loaded), while in the other, I was not expecting people to change theme for the rendered HTML. If you still experience issues, open a new issue dedicated to that.
  2. The <Markdown> component is not reactive by design. If you want to make it reactive, you should use the Svelte #key block:
{#key value}
  <Markdown {value} {carta} />
{/key}

Rendering Markdown can be pretty resources expensive, so keep that in mind.

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

No branches or pull requests

2 participants