mirror of
https://github.com/pengzhanbo/vuepress-theme-plume.git
synced 2026-04-23 10:58:13 +08:00
fix(plugin-md-power): fix stringifyAttrs parse fail (#701)
This commit is contained in:
parent
69b9d0bc3d
commit
001896b5fa
@ -151,7 +151,7 @@ export function codeTreePlugin(md: Markdown, app: App, options: CodeTreeOptions
|
||||
expanded: true,
|
||||
filepath: node.filepath,
|
||||
}
|
||||
return `<FileTreeNode${stringifyAttrs(props)}>
|
||||
return `<FileTreeNode${stringifyAttrs(props, false, ['filename', 'filepath'])}>
|
||||
<template #icon><VPIcon provider="iconify" name="${getIcon(node.filename, props.type, mode)}" /></template>
|
||||
${node.children?.length ? renderFileTree(node.children, mode) : ''}
|
||||
</FileTreeNode>`
|
||||
|
||||
@ -162,7 +162,7 @@ export function fileTreePlugin(md: Markdown, options: FileTreeOptions = {}): voi
|
||||
filename,
|
||||
level,
|
||||
}
|
||||
return `<FileTreeNode${stringifyAttrs(props)}>
|
||||
return `<FileTreeNode${stringifyAttrs(props, false, ['filename'])}>
|
||||
${renderedIcon}${renderedComment}${children.length > 0 ? renderFileTree(children, meta) : ''}
|
||||
</FileTreeNode>`
|
||||
}).join('\n')
|
||||
|
||||
@ -2,16 +2,17 @@ import { isBoolean, isNull, isNumber, isString, isUndefined, kebabCase } from '@
|
||||
|
||||
export function stringifyAttrs<T extends object = object>(
|
||||
attrs: T,
|
||||
withUndefined = false,
|
||||
withUndefinedOrNull = false,
|
||||
forceStringify: (keyof T)[] = [],
|
||||
): string {
|
||||
const result = Object.entries(attrs)
|
||||
.map(([key, value]) => {
|
||||
const k = kebabCase(key)
|
||||
if (isUndefined(value) || value === 'undefined')
|
||||
return withUndefined ? `:${k}="undefined"` : ''
|
||||
return withUndefinedOrNull ? `:${k}="undefined"` : ''
|
||||
|
||||
if (isNull(value) || value === 'null')
|
||||
return withUndefined ? `:${k}="null"` : ''
|
||||
return withUndefinedOrNull ? `:${k}="null"` : ''
|
||||
|
||||
if (value === 'true')
|
||||
value = true
|
||||
@ -25,8 +26,12 @@ export function stringifyAttrs<T extends object = object>(
|
||||
return `:${k}="${value}"`
|
||||
|
||||
// like object or array
|
||||
if (isString(value) && (value[0] === '{' || value[0] === '['))
|
||||
return `:${k}="${value.replaceAll('\"', '\'')}"`
|
||||
if (isString(value) && (value[0] === '{' || value[0] === '[')) {
|
||||
const v = value.replaceAll('\"', '\'')
|
||||
if (forceStringify.includes(key as keyof T))
|
||||
return `${k}="${v}"`
|
||||
return `:${k}="${v}"`
|
||||
}
|
||||
|
||||
const hasDynamic = key[0] === ':'
|
||||
return `${hasDynamic ? ':' : ''}${k}="${String(value)}"`
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user