import { DOMOutputSpec, MarkSpec, Mark } from 'prosemirror-model' import { ExtensionSpec, defaultExtension } from './Extension' import { Attributes } from './types' export interface MarkExtensionSpec extends ExtensionSpec { inclusive?: MarkSpec['inclusive'], excludes?: MarkSpec['excludes'], group?: MarkSpec['group'], spanning?: MarkSpec['spanning'], parseHTML?: ( this: { options: Options, }, ) => MarkSpec['parseDOM'], renderHTML?: ( this: { options: Options, }, props: { mark: Mark, attributes: { [key: string]: any }, } ) => DOMOutputSpec, createAttributes?: ( this: { options: Options, }, ) => Attributes, } export type MarkExtension = Required & { type: string, options: { [key: string]: any }, }> const defaultMark: MarkExtension = { ...defaultExtension, type: 'mark', name: 'mark', inclusive: null, excludes: null, group: null, spanning: null, parseHTML: () => null, renderHTML: () => null, createAttributes: () => ({}), } export function createMark(config: MarkExtensionSpec) { const extend = (extendedConfig: Partial>) => { return createMark({ ...config, ...extendedConfig, } as MarkExtensionSpec) } const setOptions = (options?: Partial) => { const { defaultOptions, ...rest } = config return { ...defaultMark, ...rest, options: { ...defaultOptions, ...options, } as Options, } } return Object.assign(setOptions, { config, extend }) }