Skip to content

Commit 8bd37cf

Browse files
committed
fix: fix code language detection in some edge case
1 parent dd13128 commit 8bd37cf

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

index.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ const defaultOptions = {
3131
const REGEXP_COMMENT_OPTIONS = /^(?:no-)?vue-component$/;
3232
const REGEXP_HYPHENS_END = /-*$/;
3333
const REGEXP_HYPHENS_START = /^-*/;
34-
const REGEXP_LANGUAGE_PREFIXES = /lang(uage)?-/;
34+
const REGEXP_LANGUAGE_CLASS = /\blang(?:uage)?-(\w+)\b/;
3535
const REGEXP_MODULE_EXPORTS = /(?:export\s+default|(?:module\.)?exports\s*=)/g;
3636
const REGEXP_MODULE_IMPORTS = /(?:import)(?:\s+((?:[\s\S](?!import))+?)\s+(?:from))?\s+["']([^"']+)["']/g;
3737
const REGEXP_NOT_WORDS = /\W/g;
@@ -112,7 +112,7 @@ module.exports = function markdownToVueLoader(source, map) {
112112
if (commentOption !== 'no-vue-component') {
113113
$pre.children('code').each((idx, code) => {
114114
const $code = $(code);
115-
const language = $code.attr('class').replace(REGEXP_LANGUAGE_PREFIXES, '');
115+
const [, language] = ($code.attr('class') || '').match(REGEXP_LANGUAGE_CLASS) || [];
116116

117117
if (options.languages.indexOf(language) === -1 && commentOption !== 'vue-component') {
118118
return;

0 commit comments

Comments
 (0)