@atlaskit/editor-common
Version:
A package that contains common classes and components for editor and renderer
47 lines (45 loc) • 1.53 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = _default;
/*
* 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
*/
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);
}
}
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);
}
}
function _default(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;
}, []);
});
}