Files
Yep_Q 1564396449 feat: 完善会展策划演示系统
详细说明:
- 添加了V2版本的工作流页面和结果页面
- 更新了Serena记忆文件
- 添加了详细实施计划文档
- 优化了Vite配置
- 更新了项目文档CLAUDE.md
- 构建了演示系统的dist版本
- 包含了exhibition-demo的完整依赖
2025-09-08 11:15:23 +08:00

109 lines
2.6 KiB
JavaScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/**
* @typedef {import('mdast').Nodes} Nodes
*
* @typedef Options
* Configuration (optional).
* @property {boolean | null | undefined} [includeImageAlt=true]
* Whether to use `alt` for `image`s (default: `true`).
* @property {boolean | null | undefined} [includeHtml=true]
* Whether to use `value` of HTML (default: `true`).
*/
/** @type {Options} */
const emptyOptions = {}
/**
* Get the text content of a node or list of nodes.
*
* Prefers the nodes plain-text fields, otherwise serializes its children,
* and if the given value is an array, serialize the nodes in it.
*
* @param {unknown} [value]
* Thing to serialize, typically `Node`.
* @param {Options | null | undefined} [options]
* Configuration (optional).
* @returns {string}
* Serialized `value`.
*/
export function toString(value, options) {
const settings = options || emptyOptions
const includeImageAlt =
typeof settings.includeImageAlt === 'boolean'
? settings.includeImageAlt
: true
const includeHtml =
typeof settings.includeHtml === 'boolean' ? settings.includeHtml : true
return one(value, includeImageAlt, includeHtml)
}
/**
* One node or several nodes.
*
* @param {unknown} value
* Thing to serialize.
* @param {boolean} includeImageAlt
* Include image `alt`s.
* @param {boolean} includeHtml
* Include HTML.
* @returns {string}
* Serialized node.
*/
function one(value, includeImageAlt, includeHtml) {
if (node(value)) {
if ('value' in value) {
return value.type === 'html' && !includeHtml ? '' : value.value
}
if (includeImageAlt && 'alt' in value && value.alt) {
return value.alt
}
if ('children' in value) {
return all(value.children, includeImageAlt, includeHtml)
}
}
if (Array.isArray(value)) {
return all(value, includeImageAlt, includeHtml)
}
return ''
}
/**
* Serialize a list of nodes.
*
* @param {Array<unknown>} values
* Thing to serialize.
* @param {boolean} includeImageAlt
* Include image `alt`s.
* @param {boolean} includeHtml
* Include HTML.
* @returns {string}
* Serialized nodes.
*/
function all(values, includeImageAlt, includeHtml) {
/** @type {Array<string>} */
const result = []
let index = -1
while (++index < values.length) {
result[index] = one(values[index], includeImageAlt, includeHtml)
}
return result.join('')
}
/**
* Check if `value` looks like a node.
*
* @param {unknown} value
* Thing.
* @returns {value is Nodes}
* Whether `value` is a node.
*/
function node(value) {
return Boolean(value && typeof value === 'object')
}