How to use the @sveltejs/site-kit/utils/markdown.extract_metadata function in @sveltejs/site-kit

To help you get started, we’ve selected a few @sveltejs/site-kit examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github sveltejs / svelte / site / src / routes / tutorial / [slug] / index.json.js View on Github external
renderer.code = (source, lang) => {
		source = source.replace(/^ +/gm, match =>
			match.split('    ').join('\t')
		);

		const lines = source.split('\n');

		const meta = extract_metadata(lines[0], lang);

		let prefix = '';
		let className = 'code-block';

		if (meta) {
			source = lines.slice(1).join('\n');
			const filename = meta.filename || (lang === 'html' && 'App.svelte');
			if (filename) {
				prefix = `<span class="filename">${prefix} ${filename}</span>`;
				className += ' named';
			}
		}

		return `<div class="${className}">${prefix}${highlight(source, lang)}</div>`;
	};

@sveltejs/site-kit

Styles and components for use in *.svelte.dev websites

MIT
Latest version published 1 year ago

Package Health Score

61 / 100
Full package analysis

Similar packages