BearToCode / carta

A lightweight, fast and extensible Svelte Markdown editor and viewer.
https://beartocode.github.io/carta/
MIT License
264 stars 10 forks source link

cannot work with mode-watcher #57

Closed leonwang908 closed 1 month ago

leonwang908 commented 1 month ago

carta will stop rendering stuff like highlightjs, <h1> if I do like below in +layout.svelte

import { ModeWatcher, setMode, resetMode } from 'mode-watcher';

btw, is there any easy way to add dual theme like light/dark in carta?

BearToCode commented 1 month ago

Hello,

I updated docs to include a simple explanation of how to implement a dark mode, you can check them out here, but all you have to do is the following:

/* Editor dark mode */
/* Only if you are using the default theme */
html.dark .carta-theme__default {
    --border-color: var(--border-color-dark);
    --selection-color: var(--selection-color-dark);
    --focus-outline: var(--focus-outline-dark);
    --hover-color: var(--hover-color-dark);
    --caret-color: var(--caret-color-dark);
    --text-color: var(--text-color-dark);
}

/* Code dark mode */
/* Only if you didn't specify a custom code theme */
html.dark .shiki,
html.dark .shiki span {
    color: var(--shiki-dark) !important;
}

I do not how mode-watcher works, but if it just sets a class="dark" to the root html element(or body...), it should work fine with the instructions explained above.

Let me know if this solved your issue.

leonwang908 commented 1 month ago

Hello, this one is very helpful for setting dark mode, but I still facing rendering issue.

image the elements show me <h1>test</h1> but looks like there are some css issue that cannot show heading correctly. do you have any ideas?

mjrdd commented 1 month ago

I had the same issue. But I think it is related to tailwind since it clears the default styling. You have to manually style it since the styling is not included in the default.css.

BearToCode commented 1 month ago

There are no embedded styles for the generated HTML. You can write them yourself, or use something like github-markdown-css

leonwang908 commented 1 month ago

after import github-markdown-css, My app could rendering h1. but highlightjs still not working image

and I just wondering why my app works with single carta, but if I add it to my layout it will stop working.

BearToCode commented 1 month ago

Are you using plugin-code to highlight code blocks? The issue is with them not being highlighted? Can you explain what you mean with:

and I just wondering why my app works with single carta, but if I add it to my layout it will stop working.

Does it crash, or it isn't rendering what you expected?

leonwang908 commented 1 month ago

yes, I do added plugin-code

<script>
    import { Carta, MarkdownEditor } from 'carta-md';
    import { code } from '@cartamd/plugin-code';

    import 'carta-md/default.css'; /* Default theme */

    const carta = new Carta({
        sanitizer: false,
        extensions: [code()]
    });

    let value = '';
</script>

<MarkdownEditor {carta} bind:value />

it not renderting to highlighted code, just normal code block image

BearToCode commented 1 month ago

Here is an example with everything, and it's working. Try and see where the differences are. Are you sure you are using the latest version of @cartamd/plugin-code?

leonwang908 commented 1 month ago

yes, I am using the latest version of plugin-code. and I can see <style type="text/css" data-vite-dev-id="D:/Dev/example/node_modules/.pnpm/highlight.js@11.9.0/node_modules/highlight.js/styles/github-dark-dimmed.css">hogehoge</style> in the head

the problem is like carta works well if I put it in a single new svelte project. but if I add +layout.svelte with mode-watcher, a lot of stuffs cannot rendering correctly.

BearToCode commented 1 month ago

This is very weird, I think there is something wrong with you config, as highlight.js has nothing to do with this project. And I honestly don't see a way mode-watcher could prevent the actual highlighter, Shiki, from working.

From your screenshot it looks like the language is not even parsed...

leonwang908 commented 1 month ago

oh, solved.... I should config a wrong file. (I should config /hogehoge/+page.svelte but actually I did on test/+page.svelte.

Really thanks for you help!