tiptap/packages/core/src/utils/getRenderedAttributes.ts

19 lines
564 B
TypeScript
Raw Normal View History

2020-10-22 15:14:24 +08:00
import { Node, Mark } from 'prosemirror-model'
import { ExtensionAttribute } from '../types'
2020-10-22 15:14:24 +08:00
export default function getRenderedAttributes(node: Node | Mark, attributes: ExtensionAttribute[]) {
return attributes
2020-10-22 05:35:12 +08:00
.filter(item => item.attribute.rendered)
.map(item => {
// TODO: fallback if renderHTML doesnt exist
2020-10-22 05:35:12 +08:00
return item.attribute.renderHTML(node.attrs)
})
.reduce((accumulator, value) => {
2020-10-22 05:55:14 +08:00
// TODO: add support for "class" and "style" merge
return {
...accumulator,
...value,
}
}, {})
}