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

Could not get Heading Level in Svelte Component #76

Open
BlenderBoi opened this issue Sep 10, 2023 · 1 comment
Open

Could not get Heading Level in Svelte Component #76

BlenderBoi opened this issue Sep 10, 2023 · 1 comment

Comments

@BlenderBoi
Copy link

I could not get the Heading Levels in svelte component

image

Any Pointers for me?

@yenn01
Copy link

yenn01 commented Oct 7, 2023

Hi there, not sure if this answers your question. I was trying to stylise each level of heading differently and was able to achieve that by passing a custom heading.svelte renderer which I adapted from the src.

customHeading.svelte

<script>
	export let depth;
	export let raw;
</script>

{#if depth === 1}
	<h1><slot /></h1>
{:else if depth === 2}
	<h2><slot /></h2>
{:else if depth === 3}
	<h3><slot /></h3>
{:else if depth === 4}
	<h4><slot /></h4>
{:else if depth === 5}
	<h5><slot /></h5>
{:else if depth === 6}
	<h6><slot /></h6>
{:else}
	{raw}
{/if}

<style>
	h1 {
		color: red;
	}
	h2 {
		color: green;
	}

	h3 {
		color: blue;
	}
</style>

yourMarkdownSvelteFile.svelte

<script>
	import SvelteMarkdown from 'svelte-markdown';
	import customHeading from './customHeading.svelte'
	const source =`# Header 1 
## Header 2
### Header 3
`;
</script>

<SvelteMarkdown {source} renderers={{ 
heading: customHeading
}}
/>

A REPL (unfortunately I can't get the REPL to work due to Slugger being removed from marked in v8.0.0 according to this.
https://svelte.dev/repl/3718389cd84a407b845424a8cf2335b8?version=4.2.1

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