[MFM] Fallback to js if specified lang is not available (#5347)

This commit is contained in:
Aya Morisawa 2019-08-27 19:44:49 +09:00 committed by syuilo
parent 13f69e4291
commit 9d65768d4d
1 changed files with 9 additions and 3 deletions

View File

@ -1,16 +1,16 @@
<template> <template>
<prism :inline="inline" :language="lang || 'js'">{{ code }}</prism> <x-prism :inline="inline" :language="prismLang">{{ code }}</x-prism>
</template> </template>
<script lang="ts"> <script lang="ts">
import Vue from 'vue'; import Vue from 'vue';
import 'prismjs'; import 'prismjs';
import 'prismjs/themes/prism-okaidia.css'; import 'prismjs/themes/prism-okaidia.css';
import Prism from 'vue-prism-component'; import XPrism from 'vue-prism-component';
export default Vue.extend({ export default Vue.extend({
components: { components: {
Prism XPrism
}, },
props: { props: {
code: { code: {
@ -25,6 +25,12 @@ export default Vue.extend({
type: Boolean, type: Boolean,
required: false required: false
} }
},
computed: {
prismLang() {
return Prism.languages[this.lang] ? this.lang : 'js';
}
} }
}); });
</script> </script>