UNPKG

@atlaskit/adf-schema

Version:

Shared package that contains the ADF-schema (json) and ProseMirror node/mark specs

57 lines (52 loc) 1.09 kB
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 */ const getAttrs = level => domNode => ({ level, localId: // eslint-disable-next-line @atlaskit/editor/no-as-casting domNode.getAttribute('data-local-id') || null }); export const 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(node) { const { level, localId } = node.attrs; const name = 'h' + level; const attrs = localId !== undefined && localId !== null ? [{ 'data-local-id': localId }] : []; return [name, ...attrs, 0]; } });