Skip to content

Commit be166a9

Browse files
committed
feat: added Code Inline
1 parent 8e2b543 commit be166a9

File tree

4 files changed

+45
-10
lines changed

4 files changed

+45
-10
lines changed

playground/src/App.vue

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<script setup lang="ts">
22
import { onMounted, ref } from 'vue'
3-
import { ECodeBlock, useRender } from 'vue-email'
3+
import { ECodeBlock, ECodeInline, useRender } from 'vue-email'
44
import Test from './components/Test.vue'
55
66
const email = ref('')
@@ -25,6 +25,7 @@ const tokens = await codeToThemedTokens('<div class="foo">bar</div>', {
2525
<Suspense>
2626
<ECodeBlock style="padding: 20px;" :code="code" lang="typescript" theme="dracula" />
2727
</Suspense>
28+
<ECodeInline>@vue-email/nuxt</ECodeInline>
2829
<iframe :srcdoc="email" />
2930
</template>
3031

src/components/ECodeBlock.ts

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -60,14 +60,5 @@ export default defineComponent({
6060
}),
6161
]),
6262
])
63-
64-
// const htmlCode = await codeToHtml(code, {
65-
// lang,
66-
// theme,
67-
// })
68-
69-
// return () => h('clean-component', {
70-
// innerHTML: htmlCode,
71-
// })
7263
},
7364
})

src/components/ECodeInline.ts

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import type { CSSProperties, PropType } from 'vue'
2+
import { defineComponent, h } from 'vue'
3+
4+
export default defineComponent({
5+
name: 'ECodeInline',
6+
props: {
7+
class: {
8+
type: String,
9+
default: '',
10+
},
11+
style: {
12+
type: Object as PropType<CSSProperties>,
13+
},
14+
},
15+
setup(props, { slots }) {
16+
return () =>
17+
[h('style', null, `
18+
meta ~ .cino {
19+
display: none !important;
20+
opacity: 0 !important;
21+
}
22+
23+
meta ~ .cio {
24+
display: block !important;
25+
}
26+
`), h('code', {
27+
...props,
28+
class: [
29+
props.class,
30+
'cino',
31+
],
32+
style: props.style,
33+
}, slots.default?.()), h('span', {
34+
...props,
35+
class: [
36+
props.class,
37+
'cio',
38+
],
39+
style: { ...props.style, display: 'none' },
40+
}, slots.default?.())]
41+
},
42+
})

src/components/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,4 @@ export { default as EText } from './EText'
1717
export { default as EMarkdown } from './EMarkdown'
1818
export { default as EStyle } from './EStyle'
1919
export { default as ECodeBlock } from './ECodeBlock'
20+
export { default as ECodeInline } from './ECodeInline'

0 commit comments

Comments
 (0)