tiptap/packages/core/src/utils/getRenderedAttributes.ts
Philipp Kühn faa65b5450 refactoring
2020-10-22 09:14:24 +02:00

19 lines
564 B
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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