Skip to content

Commit

Permalink
[docs] 优化加载 Demo 代码字符串高亮库的方式
Browse files Browse the repository at this point in the history
  • Loading branch information
Zhang-Wei-666 committed Aug 11, 2023
1 parent 809d2dc commit e7922d0
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions packages/.vitepress/components/DemoCard/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -24,23 +24,24 @@
import { devDependencies } from '@@/package.json';
const highlighter = ref<shiki.Highlighter>();
(async () => {
shiki.setCDN(`https://unpkg.com/shiki@${devDependencies.shiki.replace(/^\^/g, '')}/`);
highlighter.value = await shiki.getHighlighter({
langs: ['ts'],
theme: 'material-theme-darker',
});
})();
const code = ref('');
const codeHighlight = computed(() => {
return highlighter.value?.codeToHtml(code.value, { lang: 'ts' }) ?? '';
});
const hasCode = computed(() => !!code.value);
const [showCode, toggleShowCode] = useToggle(true);
const hasCode = computed(() => !!code.value);
const showExtra = computed(() => hasCode.value);
onMounted(async () => {
shiki.setCDN(`https://unpkg.com/shiki@${devDependencies.shiki.replace(/^\^/g, '')}/`);
highlighter.value = await shiki.getHighlighter({
langs: ['ts'],
theme: 'material-theme-darker',
});
});
provide('code', code);
</script>

0 comments on commit e7922d0

Please sign in to comment.