-
-
Notifications
You must be signed in to change notification settings - Fork 60
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
de8d9e0
commit d0fdf79
Showing
12 changed files
with
475 additions
and
84 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -72,6 +72,7 @@ | |
"taze", | ||
"Tongji", | ||
"tsbuildinfo", | ||
"twoslash", | ||
"vite", | ||
"vuepress", | ||
"vueuse", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
diff --git a/dist/index.js b/dist/index.js | ||
index 996b0d16dac39667cc25496e52adcc9dd2b2befa..a4c9f5ba3a20967d9a561fcc73178d9e84f48279 100644 | ||
--- a/dist/index.js | ||
+++ b/dist/index.js | ||
@@ -245,7 +245,7 @@ var codePlugin = (md, { | ||
const info = token.info ? md.utils.unescapeAll(token.info).trim() : ""; | ||
const language = resolveLanguage(info); | ||
const languageClass = `${options.langPrefix}${language.name}`; | ||
- const code = options.highlight?.(token.content, language.name, "") || md.utils.escapeHtml(token.content); | ||
+ const code = options.highlight?.(token.content, language.name, info || "") || md.utils.escapeHtml(token.content); | ||
token.attrJoin("class", languageClass); | ||
let result = code.startsWith("<pre") ? code : `<pre${slf.renderAttrs(token)}><code>${code}</code></pre>`; | ||
const useVPre = resolveVPre(info) ?? vPreBlock; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
const RE_ATTR_VALUE = /(?:^|\s+)(?<attr>[\w\d-]+)(?:=\s*(?<quote>['"])(?<value>.+?)\k<quote>)?(?:\s+|$)/ | ||
const RE_CODE_BLOCKS = /^[\w\d-]*(\s*:[\w\d-]*)?(\s*\{[\d\w-,\s]+\})?\s*/ | ||
|
||
export function resolveAttrs(info: string): { | ||
attrs: Record<string, string | boolean> | ||
rawAttrs: string | ||
} { | ||
if (!info) | ||
return { rawAttrs: '', attrs: {} } | ||
info = info.replace(RE_CODE_BLOCKS, '').trim() | ||
if (!info) | ||
return { rawAttrs: '', attrs: {} } | ||
|
||
const attrs: Record<string, string | boolean> = {} | ||
const rawAttrs = info | ||
|
||
let matched: RegExpMatchArray | null | ||
|
||
// eslint-disable-next-line no-cond-assign | ||
while (matched = info.match(RE_ATTR_VALUE)) { | ||
const { attr, value } = matched.groups || {} | ||
attrs[attr] = value ?? true | ||
info = info.slice(matched[0].length) | ||
} | ||
|
||
Object.keys(attrs).forEach((key) => { | ||
let value = attrs[key] | ||
value = typeof value === 'string' ? value.trim() : value | ||
if (value === 'true') | ||
value = true | ||
else if (value === 'false') | ||
value = false | ||
|
||
attrs[key] = value | ||
|
||
if (key.includes('-')) { | ||
const _key = key.replace(/-(\w)/g, (_, c) => c.toUpperCase()) | ||
attrs[_key] = value | ||
} | ||
}) | ||
|
||
return { attrs, rawAttrs } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.