Skip to content

Commit 50117f8

Browse files
committed
feat(docs): allow bash as lang for Code component
1 parent 4c658a6 commit 50117f8

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

src/views/components/Code.vue

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
:class="tw`px-1 py-2 bg-gray-100 dark:bg-gray-800 overflow-auto`"
55
>
66
<Prism :language="lang === 'vue' ? 'html' : lang" :inline="inline">{{
7-
prettyCode
7+
formattedCode
88
}}</Prism>
99
</div>
1010
</template>
@@ -15,6 +15,7 @@ import { tw } from "twind";
1515
import Strip from "strip-indent";
1616
import PrismJs from "prismjs";
1717
import "prismjs/components/prism-json";
18+
import "prismjs/components/prism-bash";
1819
import "prismjs/plugins/line-numbers/prism-line-numbers.js";
1920
import Prism from "vue-prism-component";
2021
import { format } from "prettier/standalone";
@@ -34,7 +35,8 @@ export default defineComponent({
3435
lang: {
3536
type: String,
3637
default: "html",
37-
validator: (v: string) => ["js", "vue", "json", "html"].includes(v),
38+
validator: (v: string) =>
39+
["js", "vue", "json", "html", "bash"].includes(v),
3840
},
3941
inline: {
4042
type: Boolean,
@@ -61,14 +63,16 @@ export default defineComponent({
6163
plugins: [prettierPluginPackage],
6264
},
6365
};
64-
const prettierConfig = prettierConfigs?.[props?.lang];
65-
const prettyCode = computed(() =>
66-
format(Strip(props.code), prettierConfig)
66+
const prettierConfig = prettierConfigs?.[props.lang] ?? false;
67+
const formattedCode = computed(() =>
68+
prettierConfig
69+
? format(Strip(props.code), prettierConfig)
70+
: Strip(props.code)
6771
);
6872
onMounted(() => {
6973
PrismJs.highlightAll();
7074
});
71-
return { prettyCode, tw };
75+
return { formattedCode, tw };
7276
},
7377
});
7478
</script>

0 commit comments

Comments
 (0)