2020-10-22 15:14:24 +08:00
|
|
|
|
import { Node, Mark } from 'prosemirror-model'
|
2020-10-22 05:32:28 +08:00
|
|
|
|
import { ExtensionAttribute } from '../types'
|
|
|
|
|
|
2020-10-22 15:42:28 +08:00
|
|
|
|
export default function getRenderedAttributes(nodeOrMark: Node | Mark, extensionAttributes: ExtensionAttribute[]): { [key: string]: any } {
|
|
|
|
|
return extensionAttributes
|
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 15:42:28 +08:00
|
|
|
|
return item.attribute.renderHTML(nodeOrMark.attrs)
|
2020-10-22 05:32:28 +08:00
|
|
|
|
})
|
2020-10-22 15:42:28 +08:00
|
|
|
|
.reduce((attributes, attribute) => {
|
2020-10-22 05:55:14 +08:00
|
|
|
|
// TODO: add support for "class" and "style" merge
|
2020-10-22 05:32:28 +08:00
|
|
|
|
return {
|
2020-10-22 15:42:28 +08:00
|
|
|
|
...attributes,
|
|
|
|
|
...attribute,
|
2020-10-22 05:32:28 +08:00
|
|
|
|
}
|
|
|
|
|
}, {})
|
|
|
|
|
}
|