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

theme setting in code() is not working well #61

Closed
leonwang908 opened this issue May 2, 2024 · 5 comments
Closed

theme setting in code() is not working well #61

leonwang908 opened this issue May 2, 2024 · 5 comments
Labels
documentation Improvements or additions to documentation

Comments

@leonwang908
Copy link

if there are no theme setting like theme: 'github-light', code will be highlighter. but if include theme setting in code(). all code will be rendering as normal code block without highlight.

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

	import './github.scss';

	const carta = new Carta({
		sanitizer: false,
		extensions: [
			code({
				theme: 'github-light',
				langs: ['html', 'js', 'ts', 'python', 'ruby', 'php', 'java', 'c', 'csharp', 'cpp', 'css', 'sql', 'swift', 'go', 'kotlin', 'rust', 'bash', 'scala', 'julia', 'powershell', 'json', 'xml', 'yaml', 'latex', 'r', 'dart']
			})
		]
	});

	export let value = `This is an example inspired by [GitHub](https://github.com)
\`\`\`js
console.log('Hello, World!');
\`\`\`

\`\`\`python
def sum(a, b):
	return a + b
\`\`\`

`;
</script>

<MarkdownEditor bind:value mode="tabs" theme="github" {carta} />

<style>
	:global(.shiki),
	:global(.shiki span) {
		color: var(--shiki-dark) !important;
	}

	:global(button) {
		background: transparent;
		border: 0;
	}
</style>

image

@leonwang908
Copy link
Author

btw, setting of 'langs' looks like ingored
image

@BearToCode
Copy link
Owner

Hello;
you need to load the theme beforehand:

const carta = new Carta({
  // ...
  code({
    theme: 'github-light',
  }),
  shikiOptions: {
    themes: ['github-light']
  }
})

I'll add that to the docs.
Since you are not using a dual theme, make sure to remove the dual-theme related css, if you had it, otherwise you'll still see it as white. I think it's not required to specify standard languages in langs, but to be honest I'm not 100% sure. If in the future you see them not working, try explicitly adding them

@BearToCode BearToCode added the documentation Improvements or additions to documentation label May 2, 2024
@leonwang908
Copy link
Author

solved, thank you very much! I super love you editor, if there are more detail document it will be very helpful.

btw, just wondering. I thought only language set in langs will be rendering, but looks like all language will be render in some rule?

@leonwang908
Copy link
Author

image

Hello, there is the issue that setting of langs is ingored.
when build project it will create a lot of huge js that no needed. it will decrease loading speed.

@BearToCode
Copy link
Owner

BearToCode commented May 2, 2024

Don't worry, those languages are bundled into the output directory. This does not mean they are automatically imported with the editor. In fact, if you go to your editor and start using an additional language while having the network tab open, you'll see that languages are imported only when needed.

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation
Projects
None yet
Development

No branches or pull requests

2 participants