\n`
+ before(info) {
+ const title = resolveAttr(info, 'title')
+ const wrapperClasses: string[] = ['demo-wrapper']
+ let containerStyle = ''
+ if (title)
+ wrapperClasses.push('has-title')
+
+ if (info.includes('img'))
+ wrapperClasses.push('only-img')
+
+ if (info.includes('no-padding'))
+ wrapperClasses.push('no-padding')
+
+ const height = resolveAttr(info, 'height')
+ if (height) {
+ const h = Number.parseFloat(height) === Number(height) ? `${height}px` : height
+ containerStyle += `--demo-container-height: ${h};`
+ wrapperClasses.push('has-height')
+ }
+
+ return `
+
+
+ ${title ? `
${title}
` : ''}
+
+
\n`
},
after() {
return '
\n'
},
}),
]
+
+/**
+ * Resolve the specified attribute from token info
+ */
+function resolveAttr(info: string, attr: string): string | null {
+ // try to match specified attr mark
+ const pattern = `\\b${attr}\\s*=\\s*(?
['"])(?.+?)\\k(\\s|$)`
+ const regex = new RegExp(pattern, 'i')
+ const match = info.match(regex)
+
+ // return content if matched, null if not specified
+ return match?.groups?.content ?? null
+}