@atlaskit/adf-schema
Version:
Shared package that contains the ADF-schema (json) and ProseMirror node/mark specs
60 lines (55 loc) • 1.23 kB
JavaScript
import { heading as headingFactory } from '../../next-schema/generated/nodeTypes';
/**
* @name heading_node
*/
/**
* @name heading_with_no_marks_node
*/
// Check `paragraph` node for why we are doing things like this
/**
* @name heading_with_alignment_node
*/
/**
* @name heading_with_indentation_node
*/
var getAttrs = function getAttrs(level) {
return function (domNode) {
return {
level: level,
localId:
// eslint-disable-next-line @atlaskit/editor/no-as-casting
domNode.getAttribute('data-local-id') || null
};
};
};
export var heading = headingFactory({
parseDOM: [{
tag: 'h1',
getAttrs: getAttrs(1)
}, {
tag: 'h2',
getAttrs: getAttrs(2)
}, {
tag: 'h3',
getAttrs: getAttrs(3)
}, {
tag: 'h4',
getAttrs: getAttrs(4)
}, {
tag: 'h5',
getAttrs: getAttrs(5)
}, {
tag: 'h6',
getAttrs: getAttrs(6)
}],
toDOM: function toDOM(node) {
var _node$attrs = node.attrs,
level = _node$attrs.level,
localId = _node$attrs.localId;
var name = 'h' + level;
var attrs = localId !== undefined && localId !== null ? [{
'data-local-id': localId
}] : [];
return [name].concat(attrs, [0]);
}
});