File tree Expand file tree Collapse file tree 3 files changed +25
-5
lines changed Expand file tree Collapse file tree 3 files changed +25
-5
lines changed Original file line number Diff line number Diff line change 4
4
class =" my-class"
5
5
id =" my-id"
6
6
:code =" code"
7
- language =" py "
7
+ language =" python "
8
8
code-class =" codeClass"
9
9
:lines-highlighted =" [1, 2]"
10
10
:words-highlighted =" ['log']"
Original file line number Diff line number Diff line change @@ -4,6 +4,7 @@ import type {
4
4
MaybeRefOrGetter ,
5
5
PropType
6
6
} from 'vue' ;
7
+ import { AllLanguagesSupported } from '../utils' ;
7
8
8
9
// Props goes here
9
10
export const codeBlockProps = ( ) =>
@@ -23,7 +24,7 @@ export const codeBlockProps = () =>
23
24
required : true
24
25
} ,
25
26
language : {
26
- type : String as PropType < string > ,
27
+ type : String as PropType < AllLanguagesSupported > ,
27
28
required : false ,
28
29
default : 'markup'
29
30
} ,
Original file line number Diff line number Diff line change 1
1
import 'prismjs/themes/prism.min.css' ;
2
- // import 'prismjs/themes/prism-con.min.css';
3
2
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
+
4
23
5
24
export function highlightedCode ( code : string , language : string ) {
6
25
if ( code === null || code === undefined ) {
@@ -12,10 +31,10 @@ export function highlightedCode(code: string, language: string) {
12
31
}
13
32
14
33
// 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 ] ;
16
35
17
- console . log ( "Prism component for language '" + language + "' was not found." ) ;
18
36
if ( ! prismLanguage ) {
37
+ console . log ( "Prism component for language '" + language + "' was not found." ) ;
19
38
throw new Error (
20
39
`Prism component for language "${ language } " was not found. Report this issue at https://github.com/hetari/vuejs-code-block`
21
40
) ;
You can’t perform that action at this time.
0 commit comments