UNPKG

@atlaskit/editor-common

Version:

A package that contains common classes and components for editor and renderer

46 lines (44 loc) 1.59 kB
/* * ED-15646 * Headings in list items are not supported in our schema. * As the markdown transformer is used by the paste plugin, * certain pastes will strip invalid lines as * prosemirror-markdown cannot conform to the schema */ // Ignored via go/ees005 // eslint-disable-next-line @typescript-eslint/max-params function handleHeadingOpen(state, token, acc, index) { var _state$tokens; var isInListItem = ((_state$tokens = state.tokens[index - 1]) === null || _state$tokens === void 0 ? void 0 : _state$tokens.type) === 'list_item_open'; if (isInListItem) { acc.push(new state.Token('paragraph_open', 'p', 1)); } else { acc.push(token); } } // Ignored via go/ees005 // eslint-disable-next-line @typescript-eslint/max-params function handleHeadingClose(state, token, acc, index) { var _state$tokens2; var isInListItem = ((_state$tokens2 = state.tokens[index + 1]) === null || _state$tokens2 === void 0 ? void 0 : _state$tokens2.type) === 'list_item_close'; if (isInListItem) { acc.push(new state.Token('paragraph_close', 'p', -1)); } else { acc.push(token); } } export default function (md) { md.core.ruler.after('inline', 'ignore-list-heading-md-plugin', function (state) { state.tokens = state.tokens.reduce(function (acc, token, index) { var type = token.type; if (type === 'heading_open') { handleHeadingOpen(state, token, acc, index); } else if (type === 'heading_close') { handleHeadingClose(state, token, acc, index); } else { acc.push(token); } return acc; }, []); }); }