${title ? `
${title}
` : ''}`
}
else {
@@ -69,6 +81,20 @@ export function fileTreePlugin(md: Markdown) {
md.use(container, type, { validate, render })
}
+function getFileIconMode(info: string): FileTreeIconMode | undefined {
+ if (RE_SIMPLE_ICON.test(info))
+ return 'simple'
+ if (RE_COLORED_ICON.test(info))
+ return 'colored'
+ return undefined
+}
+
+function resolveTitle(info: string): string {
+ info = info.trim().slice(type.length).trim()
+ info = info.replace(RE_SIMPLE_ICON, '').replace(RE_COLORED_ICON, '')
+ return info.trim()
+}
+
export function resolveTreeNodeInfo(
tokens: Token[],
current: Token,
diff --git a/plugins/plugin-md-power/src/node/container/index.ts b/plugins/plugin-md-power/src/node/container/index.ts
index 9b4ae23f..f76d98f4 100644
--- a/plugins/plugin-md-power/src/node/container/index.ts
+++ b/plugins/plugin-md-power/src/node/container/index.ts
@@ -1,6 +1,7 @@
import type { App } from 'vuepress'
import type { Markdown } from 'vuepress/markdown'
import type { MarkdownPowerPluginOptions } from '../../shared/index.js'
+import { isPlainObject } from '@vuepress/helper'
import { alignPlugin } from './align.js'
import { codeTabs } from './codeTabs.js'
import { fileTreePlugin } from './fileTree.js'
@@ -17,13 +18,13 @@ export async function containerPlugin(
// ::: tabs
tabs(md)
// ::: code-tabs
- codeTabs(md)
+ codeTabs(md, options.codeTabs)
if (options.repl)
await langReplPlugin(app, md, options.repl)
if (options.fileTree) {
// ::: file-tree
- fileTreePlugin(md)
+ fileTreePlugin(md, isPlainObject(options.fileTree) ? options.fileTree : {})
}
}
diff --git a/plugins/plugin-md-power/src/node/fileIcons/findIcon.ts b/plugins/plugin-md-power/src/node/fileIcons/findIcon.ts
index 8cc28aef..d123ed60 100644
--- a/plugins/plugin-md-power/src/node/fileIcons/findIcon.ts
+++ b/plugins/plugin-md-power/src/node/fileIcons/findIcon.ts
@@ -30,7 +30,7 @@ export function getFileIconName(fileName: string, type: 'file' | 'folder' = 'fil
return icon
}
-function getFileIconTypeFromExtension(fileName: string): string | undefined {
+export function getFileIconTypeFromExtension(fileName: string): string | undefined {
const firstDotIndex = fileName.indexOf('.')
if (firstDotIndex === -1)
return
diff --git a/plugins/plugin-md-power/src/node/inline/icons.ts b/plugins/plugin-md-power/src/node/inline/icons.ts
index b6eddedb..8956f3e3 100644
--- a/plugins/plugin-md-power/src/node/inline/icons.ts
+++ b/plugins/plugin-md-power/src/node/inline/icons.ts
@@ -6,13 +6,14 @@
*/
import type { PluginWithOptions } from 'markdown-it'
import type { RuleInline } from 'markdown-it/lib/parser_inline.mjs'
+import type { IconsOptions } from '../../shared/index.js'
const [openTag, endTag] = [':[', ']:']
-export const iconsPlugin: PluginWithOptions
= md =>
- md.inline.ruler.before('emphasis', 'iconify', createTokenizer())
+export const iconsPlugin: PluginWithOptions = (md, options = {}) =>
+ md.inline.ruler.before('emphasis', 'iconify', createTokenizer(options))
-function createTokenizer(): RuleInline {
+function createTokenizer(options: IconsOptions): RuleInline {
return (state, silent) => {
let found = false
const max = state.posMax
@@ -56,8 +57,8 @@ function createTokenizer(): RuleInline {
state.posMax = state.pos
state.pos = start + 2
- const [name, options = ''] = content.split(/\s+/)
- const [size, color] = options.split('/')
+ const [name, opt = ''] = content.split(/\s+/)
+ const [size = options.size, color = options.color] = opt.split('/')
const icon = state.push('vp_iconify_open', 'VPIcon', 1)
icon.markup = openTag
@@ -65,7 +66,7 @@ function createTokenizer(): RuleInline {
if (name)
icon.attrSet('name', name)
if (size)
- icon.attrSet('size', size)
+ icon.attrSet('size', String(size))
if (color)
icon.attrSet('color', color)
diff --git a/plugins/plugin-md-power/src/node/inline/index.ts b/plugins/plugin-md-power/src/node/inline/index.ts
index 536960b1..92e52d62 100644
--- a/plugins/plugin-md-power/src/node/inline/index.ts
+++ b/plugins/plugin-md-power/src/node/inline/index.ts
@@ -6,6 +6,7 @@ import { mark } from '@mdit/plugin-mark'
import { sub } from '@mdit/plugin-sub'
import { sup } from '@mdit/plugin-sup'
import { tasklist } from '@mdit/plugin-tasklist'
+import { isPlainObject } from '@vuepress/helper'
import { iconsPlugin } from './icons.js'
import { plotPlugin } from './plot.js'
@@ -22,12 +23,12 @@ export function inlineSyntaxPlugin(
if (options.icons) {
// :[collect:name]:
- md.use(iconsPlugin)
+ md.use(iconsPlugin, isPlainObject(options.icons) ? options.icons : {})
}
if (
options.plot === true
- || (typeof options.plot === 'object' && options.plot.tag !== false)
+ || (isPlainObject(options.plot) && options.plot.tag !== false)
) {
// !!plot!!
md.use(plotPlugin)
diff --git a/plugins/plugin-md-power/src/node/plugin.ts b/plugins/plugin-md-power/src/node/plugin.ts
index 07a5e43a..45671e6a 100644
--- a/plugins/plugin-md-power/src/node/plugin.ts
+++ b/plugins/plugin-md-power/src/node/plugin.ts
@@ -7,7 +7,9 @@ import { imageSizePlugin } from './enhance/imageSize.js'
import { inlineSyntaxPlugin } from './inline/index.js'
import { prepareConfigFile } from './prepareConfigFile.js'
-export function markdownPowerPlugin(options: MarkdownPowerPluginOptions = {}): Plugin {
+export function markdownPowerPlugin(
+ options: MarkdownPowerPluginOptions = {},
+): Plugin {
return {
name: 'vuepress-plugin-md-power',
@@ -19,11 +21,7 @@ export function markdownPowerPlugin(options: MarkdownPowerPluginOptions = {}): P
extendsBundlerOptions(bundlerOptions, app) {
if (options.repl) {
- addViteOptimizeDepsInclude(
- bundlerOptions,
- app,
- ['shiki/core', 'shiki/wasm'],
- )
+ addViteOptimizeDepsInclude(bundlerOptions, app, ['shiki/core', 'shiki/wasm'])
}
},
diff --git a/plugins/plugin-md-power/src/shared/codeTabs.ts b/plugins/plugin-md-power/src/shared/codeTabs.ts
new file mode 100644
index 00000000..6e2bea8a
--- /dev/null
+++ b/plugins/plugin-md-power/src/shared/codeTabs.ts
@@ -0,0 +1,3 @@
+export interface CodeTabsOptions {
+ icon?: boolean | { named?: false | string[], extensions?: false | string[] }
+}
diff --git a/plugins/plugin-md-power/src/shared/fileTree.ts b/plugins/plugin-md-power/src/shared/fileTree.ts
new file mode 100644
index 00000000..e3070e01
--- /dev/null
+++ b/plugins/plugin-md-power/src/shared/fileTree.ts
@@ -0,0 +1,5 @@
+export type FileTreeIconMode = 'simple' | 'colored'
+
+export interface FileTreeOptions {
+ icon?: FileTreeIconMode
+}
diff --git a/plugins/plugin-md-power/src/shared/icons.ts b/plugins/plugin-md-power/src/shared/icons.ts
index 93ef6e56..9c249ea2 100644
--- a/plugins/plugin-md-power/src/shared/icons.ts
+++ b/plugins/plugin-md-power/src/shared/icons.ts
@@ -1,10 +1,4 @@
export interface IconsOptions {
- /**
- * The prefix of the icon className
- * @default 'vp-mdi'
- */
- prefix?: string
-
/**
* The size of the icon
* @default '1em'
diff --git a/plugins/plugin-md-power/src/shared/index.ts b/plugins/plugin-md-power/src/shared/index.ts
index 60ab43fc..beb2af52 100644
--- a/plugins/plugin-md-power/src/shared/index.ts
+++ b/plugins/plugin-md-power/src/shared/index.ts
@@ -1,6 +1,8 @@
export * from './caniuse.js'
export * from './codepen.js'
export * from './codeSandbox.js'
+export * from './codeTabs.js'
+export * from './fileTree.js'
export * from './icons.js'
export * from './jsfiddle.js'
export * from './pdf.js'
@@ -8,7 +10,5 @@ export * from './plot.js'
export * from './plugin.js'
export * from './repl.js'
export * from './replit.js'
-
export * from './size.js'
-
export * from './video.js'
diff --git a/plugins/plugin-md-power/src/shared/plugin.ts b/plugins/plugin-md-power/src/shared/plugin.ts
index becbe6c6..3fcf28e9 100644
--- a/plugins/plugin-md-power/src/shared/plugin.ts
+++ b/plugins/plugin-md-power/src/shared/plugin.ts
@@ -1,10 +1,16 @@
import type { CanIUseOptions } from './caniuse.js'
+import type { CodeTabsOptions } from './codeTabs.js'
+import type { FileTreeOptions } from './fileTree.js'
import type { IconsOptions } from './icons.js'
import type { PDFOptions } from './pdf.js'
import type { PlotOptions } from './plot.js'
import type { ReplOptions } from './repl.js'
export interface MarkdownPowerPluginOptions {
+ /**
+ * 配置代码块分组
+ */
+ codeTabs?: CodeTabsOptions
/**
* 是否启用 PDF 嵌入语法
*
@@ -92,7 +98,7 @@ export interface MarkdownPowerPluginOptions {
*
* @default false
*/
- fileTree?: boolean
+ fileTree?: boolean | FileTreeOptions
/**
* 是否启用 caniuse 嵌入语法
diff --git a/theme/src/client/components/global/VPLinkCard.vue b/theme/src/client/components/global/VPLinkCard.vue
index 991ef701..e3398147 100644
--- a/theme/src/client/components/global/VPLinkCard.vue
+++ b/theme/src/client/components/global/VPLinkCard.vue
@@ -13,7 +13,7 @@ defineProps<{
-
+