Skip to content

Commit

Permalink
refactor: minor refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
asmyshlyaev177 committed Nov 16, 2024
1 parent 2e81c9e commit c2d65ca
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions packages/example-nextjs14/src/app/highlighter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,10 @@ export const createHighlighter = async () =>

export let highlighter: HighlighterCore;


export const highlight = async (content: string) => {
if (!highlighter) {
highlighter = await createHighlighter();
}
highlighter = await getHighlighter();

return (
highlighter?.codeToHtml?.(content, {
lang: 'typescript',
Expand All @@ -54,3 +54,11 @@ export const highlight = async (content: string) => {
}) || ''
);
};

async function getHighlighter() {
if (!highlighter) {
highlighter = await createHighlighter();
}
return highlighter
}

0 comments on commit c2d65ca

Please sign in to comment.