/**
 * @license Copyright (c) 2017-2025, CKSource Holding sp. z o.o. All rights reserved.
 * For licensing, see LICENSE.md.
 */

import { codeToHtml } from 'shiki';

export async function highlightCode( codeString, lang ) {
	const highlightedHTML = await codeToHtml( codeString.trim(), {
		lang,
		theme: 'github-light'
	} );

	const highlightedHTMLWithTabsInsteadOfSpaces = highlightedHTML.replaceAll( / {4}/g, '	' );
	const highlightedHTMLWithClasses = highlightedHTMLWithTabsInsteadOfSpaces.replaceAll( 'shiki', `shiki ${ lang }` );

	return highlightedHTMLWithClasses;
}
