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

Code Indentation in prop src #34

Open
TimJJTing opened this issue Feb 17, 2025 · 0 comments
Open

Code Indentation in prop src #34

TimJJTing opened this issue Feb 17, 2025 · 0 comments

Comments

@TimJJTing
Copy link

TimJJTing commented Feb 17, 2025

Hi, first of all thanks for the work. This is a hero for the project that I'm working on.

I am trying write my own wrapper because I want to use shiki as the syntax highlighter. This is what I have so far:

<script module>
	import { createHighlighter } from 'shiki';
	
	const _highlighter = await createHighlighter({
		themes: ['poimandres'],
		langs: ['svelte']
	});
	await _highlighter.loadLanguage('svelte');

	/**
	 * @param {string} code
	 * @param {string} lang
	 */
	function highlighter(code, lang = 'svelte') {
		const html = _highlighter.codeToHtml(code, { lang, theme: 'poimandres' });
		return html;
	}
</script>

<script>
	let { src = undefined, meta = undefined, example, code } = $props();
</script>

<div class="my-8">
	<div class="flex flex-col w-full rounded-b-md">
		<div class="flex justify-center shadow-inner rounded-t-md">
			<div class="flex justify-center items-center min-h-12 py-4">
				{@render example?.()}
			</div>
		</div>
		{@html highlighter(src)}
	</div>
</div>

<style>
	:global(pre) {
		margin: 0;
	}
</style>

It works, except code indentation is gone. Is there any way to preserve code indentation as the default wrapper does?

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

1 participant