tiptap/packages/core/src/helpers/getRenderedAttributes.ts
Philipp Kühn e07a5b625d
refactor: Use named exports instead of default exports (#2238)
* use named exports instead of default exports

* fix tests

Co-authored-by: Philipp Kühn <philippkuehn@MacBook-Pro-von-Philipp.local>
2021-12-06 12:00:09 +01:00

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), {})
}