Skip to content

Commit 990d06f

Browse files
committed
add: all languages supported types
1 parent c5c9f86 commit 990d06f

File tree

3 files changed

+25
-5
lines changed

3 files changed

+25
-5
lines changed

src/App.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
class="my-class"
55
id="my-id"
66
:code="code"
7-
language="py"
7+
language="python"
88
code-class="codeClass"
99
:lines-highlighted="[1, 2]"
1010
:words-highlighted="['log']"

src/components/code-block/types.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import type {
44
MaybeRefOrGetter,
55
PropType
66
} from 'vue';
7+
import { AllLanguagesSupported } from '../utils';
78

89
// Props goes here
910
export const codeBlockProps = () =>
@@ -23,7 +24,7 @@ export const codeBlockProps = () =>
2324
required: true
2425
},
2526
language: {
26-
type: String as PropType<string>,
27+
type: String as PropType<AllLanguagesSupported>,
2728
required: false,
2829
default: 'markup'
2930
},

src/components/utils.ts

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,25 @@
11
import 'prismjs/themes/prism.min.css';
2-
// import 'prismjs/themes/prism-con.min.css';
32
import { Prism } from './prism-langs';
3+
// import 'prismjs/themes/prism-con.min.css';
4+
5+
export type AllLanguagesSupported =
6+
'markup' |
7+
'jsx' |
8+
'tsx' |
9+
'swift' |
10+
'kotlin' |
11+
'objectivec' |
12+
'js-extras' |
13+
'reason' |
14+
'rust' |
15+
'graphql' |
16+
'yaml' |
17+
'go' |
18+
'cpp' |
19+
'markdown' |
20+
'python' |
21+
'json';
22+
423

524
export function highlightedCode(code: string, language: string) {
625
if (code === null || code === undefined) {
@@ -12,10 +31,10 @@ export function highlightedCode(code: string, language: string) {
1231
}
1332

1433
// Check if the language is registered, fallback to 'markup' if not found
15-
const prismLanguage = Prism.languages[language] || Prism.languages.markup;
34+
const prismLanguage = Prism.languages[language];
1635

17-
console.log("Prism component for language '" + language + "' was not found.");
1836
if (!prismLanguage) {
37+
console.log("Prism component for language '" + language + "' was not found.");
1938
throw new Error(
2039
`Prism component for language "${language}" was not found. Report this issue at https://github.com/hetari/vuejs-code-block`
2140
);

0 commit comments

Comments
 (0)