-
-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5c6b798
commit 17b90df
Showing
6 changed files
with
320 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export type { CodeOptions } from './index.vue' | ||
export { default as Code } from './index.vue' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
<script setup lang="ts"> | ||
import { defineWidget } from '@vue-motion/core' | ||
import { WidgetOptions, widget } from '@vue-motion/lib' | ||
import { CodeToHastOptions, codeToHtml } from 'shiki' | ||
import { ref, useSlots } from 'vue'; | ||
export interface CodeOptions extends WidgetOptions { | ||
shikiOptions?: CodeToHastOptions | ||
lang: string | ||
theme: string | ||
width: number | ||
height: number | ||
} | ||
const props = defineProps<CodeOptions>() | ||
const options = defineWidget<CodeOptions>(props) | ||
const slots = useSlots() | ||
const codes = slots.default ? slots.default().map(vnode => vnode.children).join('') : '' | ||
const content = ref(await codeToHtml(codes, { | ||
...options.shikiOptions, | ||
lang: options.lang, | ||
theme: options.theme, | ||
})) | ||
</script> | ||
|
||
<template> | ||
<g v-bind="widget(options)"> | ||
<foreignObject x="20" y="20" :width="options.width" :height="options.height"> | ||
<!-- | ||
In the context of SVG embeded into HTML, the XHTML namespace could | ||
be avoided, but it is mandatory in the context of an SVG document | ||
--> | ||
<div xmlns="http://www.w3.org/1999/xhtml" style="color: white" v-html="content"></div> | ||
</foreignObject> | ||
</g> | ||
</template> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.