-
Notifications
You must be signed in to change notification settings - Fork 19
Add Vue example #42
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Add Vue example #42
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<script setup lang="ts"> | ||
import SpeedHighlight from 'SpeedHighlight.vue' | ||
|
||
import { ref } from 'vue' | ||
|
||
const myCode = ref(`printf('Hello World!\n');`) | ||
const myLang = ref('c') | ||
</script> | ||
|
||
<template> | ||
<p>Here is a the example code:</p> | ||
<SpeedHighlight :content="myCode" :lang="myLang" /> | ||
</template> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# VueJs 3.x Example of a Speed Highlight Component | ||
|
||
## Install | ||
|
||
```console | ||
$ pnpm i @speed-highlight/core | ||
``` | ||
|
||
## SpeedHighlight.vue | ||
|
||
This is a simple component that wraps `speed-highlight` and makes it easier to use in your Vue app. | ||
It takes two props: `content` & `lang` - and you can include it in your pages like this: | ||
|
||
```vue | ||
<SpeedHighlight content="printf('Hello World!\n');" lang="c" /> | ||
``` | ||
|
||
## App.vue | ||
|
||
Simplified example page/parent, to show how you include `<SpeedHighlight />` on a page. |
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The filename has a typo |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<script lang="ts" setup> | ||
import { defineProps, ref, onMounted } from 'vue' | ||
import { highlightText } from '@speed-highlight/core' | ||
import '@speed-highlight/core/dist/themes/default.css' | ||
|
||
const { content = '', lang = 'c' } = defineProps<{ content: string; lang: string }>() | ||
|
||
const highlightedCode = ref('') | ||
|
||
onMounted(async () => { | ||
highlightedCode.value = await highlightText(content, lang) | ||
}) | ||
Comment on lines
+6
to
+12
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not very familiar with Vue, but it seems like the code isn't reactive to updates in the props value. It might be better to make it reactive to the props |
||
</script> | ||
|
||
<template> | ||
<div :class="`shj-lang-${lang}`" v-html="highlightedCode"></div> | ||
</template> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's better to stick with npm in the installation guide for clarity