refactoring

This commit is contained in:
Philipp Kühn
2020-10-22 09:42:28 +02:00
parent 5a2417fa53
commit 9697d585fe
6 changed files with 51 additions and 112 deletions

View File

@@ -1,18 +1,18 @@
import { Node, Mark } from 'prosemirror-model'
import { ExtensionAttribute } from '../types'
export default function getRenderedAttributes(node: Node | Mark, attributes: ExtensionAttribute[]) {
return attributes
export default function getRenderedAttributes(nodeOrMark: Node | Mark, extensionAttributes: ExtensionAttribute[]): { [key: string]: any } {
return extensionAttributes
.filter(item => item.attribute.rendered)
.map(item => {
// TODO: fallback if renderHTML doesnt exist
return item.attribute.renderHTML(node.attrs)
return item.attribute.renderHTML(nodeOrMark.attrs)
})
.reduce((accumulator, value) => {
.reduce((attributes, attribute) => {
// TODO: add support for "class" and "style" merge
return {
...accumulator,
...value,
...attributes,
...attribute,
}
}, {})
}