mirror of
https://github.com/ueberdosis/tiptap.git
synced 2024-12-22 16:17:50 +08:00
e07a5b625d
* use named exports instead of default exports * fix tests Co-authored-by: Philipp Kühn <philippkuehn@MacBook-Pro-von-Philipp.local>
19 lines
662 B
TypeScript
19 lines
662 B
TypeScript
import { Node, Mark } from 'prosemirror-model'
|
|
import { ExtensionAttribute } from '../types'
|
|
import { mergeAttributes } from '../utilities/mergeAttributes'
|
|
|
|
export function getRenderedAttributes(nodeOrMark: Node | Mark, extensionAttributes: ExtensionAttribute[]): Record<string, any> {
|
|
return extensionAttributes
|
|
.filter(item => item.attribute.rendered)
|
|
.map(item => {
|
|
if (!item.attribute.renderHTML) {
|
|
return {
|
|
[item.name]: nodeOrMark.attrs[item.name],
|
|
}
|
|
}
|
|
|
|
return item.attribute.renderHTML(nodeOrMark.attrs) || {}
|
|
})
|
|
.reduce((attributes, attribute) => mergeAttributes(attributes, attribute), {})
|
|
}
|