improve attribute handling
This commit is contained in:
@@ -7,8 +7,8 @@ export type Extensions = (Extension | NodeExtension | MarkExtension)[]
|
||||
export type Attribute = {
|
||||
default: any,
|
||||
rendered?: boolean,
|
||||
renderHTML?: ((attributes: { [key: string]: any }) => any) | null,
|
||||
parseHTML?: ((element: HTMLElement) => { [key: string]: any }) | null,
|
||||
renderHTML?: ((attributes: { [key: string]: any }) => { [key: string]: any } | null) | null,
|
||||
parseHTML?: ((element: HTMLElement) => { [key: string]: any } | null) | null,
|
||||
}
|
||||
|
||||
export type Attributes = {
|
||||
|
||||
@@ -12,7 +12,7 @@ export default function getRenderedAttributes(nodeOrMark: Node | Mark, extension
|
||||
}
|
||||
}
|
||||
|
||||
return item.attribute.renderHTML(nodeOrMark.attrs)
|
||||
return item.attribute.renderHTML(nodeOrMark.attrs) || {}
|
||||
})
|
||||
.reduce((attributes, attribute) => {
|
||||
return mergeAttributes(attributes, attribute)
|
||||
|
||||
@@ -27,7 +27,7 @@ export default function injectExtensionAttributesToParseRule(parseRule: ParseRul
|
||||
.filter(item => item.attribute.rendered)
|
||||
.reduce((items, item) => {
|
||||
const attributes = item.attribute.parseHTML
|
||||
? item.attribute.parseHTML(node as HTMLElement)
|
||||
? item.attribute.parseHTML(node as HTMLElement) || {}
|
||||
: {
|
||||
[item.name]: (node as HTMLElement).getAttribute(item.name),
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user