mirror of
https://gitee.com/ccnetcore/Yi
synced 2026-03-03 00:00:58 +08:00
18 lines
339 B
TypeScript
18 lines
339 B
TypeScript
import Prism from 'prismjs';
|
|
|
|
export function usePrism() {
|
|
const highlight = (code: string, lang: string) => {
|
|
try {
|
|
const grammar = Prism.languages[lang];
|
|
if (grammar) {
|
|
return Prism.highlight(code, grammar, lang);
|
|
}
|
|
return code;
|
|
}
|
|
catch {
|
|
return code;
|
|
}
|
|
};
|
|
return highlight;
|
|
}
|