tiptap/packages/core/src/utils/markHasAttributes.ts

16 lines
486 B
TypeScript
Raw Normal View History

2020-10-05 23:12:57 +08:00
import { EditorState } from 'prosemirror-state'
import { MarkType } from 'prosemirror-model'
import getMarkAttrs from './getMarkAttrs'
2020-10-08 09:44:18 +08:00
export default function markHasAttributes(state: EditorState, type: MarkType, attrs?: { [key: string]: any }) {
if (attrs === undefined) {
return true
}
const originalAttrs: { [key: string]: any } = getMarkAttrs(state, type)
return Object.keys(attrs).filter((key: string) => {
return attrs[key] === originalAttrs[key]
}).length
2020-10-05 23:12:57 +08:00
}