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