2020-10-22 15:14:24 +08:00
|
|
|
import { Node, Mark } from 'prosemirror-model'
|
2021-04-21 15:43:31 +08:00
|
|
|
import { ExtensionAttribute } from '../types'
|
2021-12-06 19:00:09 +08:00
|
|
|
import { mergeAttributes } from '../utilities/mergeAttributes'
|
2020-10-22 05:32:28 +08:00
|
|
|
|
2021-12-06 19:00:09 +08:00
|
|
|
export function getRenderedAttributes(nodeOrMark: Node | Mark, extensionAttributes: ExtensionAttribute[]): Record<string, any> {
|
2020-10-22 15:42:28 +08:00
|
|
|
return extensionAttributes
|
2020-10-22 05:35:12 +08:00
|
|
|
.filter(item => item.attribute.rendered)
|
|
|
|
.map(item => {
|
2020-10-25 05:53:56 +08:00
|
|
|
if (!item.attribute.renderHTML) {
|
2020-10-24 19:48:41 +08:00
|
|
|
return {
|
2020-10-27 18:54:58 +08:00
|
|
|
[item.name]: nodeOrMark.attrs[item.name],
|
2020-10-24 19:48:41 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-10-27 21:53:08 +08:00
|
|
|
return item.attribute.renderHTML(nodeOrMark.attrs) || {}
|
2020-10-22 05:32:28 +08:00
|
|
|
})
|
2021-09-23 04:45:27 +08:00
|
|
|
.reduce((attributes, attribute) => mergeAttributes(attributes, attribute), {})
|
2020-10-22 05:32:28 +08:00
|
|
|
}
|