Appearance
stripMarks
ProseMirror 维度的 marks 清理纯函数:按名称整体移除 mark,或按 mark 名移除指定属性(属性清空后自动移除该 mark)。无任何变化时返回原数组引用。
用法
ts
import { stripMarks } from '@qingpai/utils'
// 整体移除 bold mark,并从 textStyle 上移除 fontSize 属性
const marks = stripMarks(node.marks, {
markNames: ['bold'],
attrs: { textStyle: ['fontSize'] },
})参数
| 名称 | 类型 | 描述 |
|---|---|---|
marks | readonly Mark[] | 要清理的 mark 数组 |
options.markNames? | string[] | 需要整体移除的 mark 名称 |
options.attrs? | Record<string, string[]> | 需要移除的属性,按 mark 名分组,如 { textStyle: ['fontSize'] } |
返回值
readonly Mark[] — 清理后的 mark 数组;无变化时返回原引用。
TIP
需要对整个 Fragment 批量清理时,使用 stripMarksFromFragment。