@atlaskit/editor-core
Version:
A package contains Atlassian editor core functionality
32 lines • 1.65 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
var prosemirror_1 = require("../../prosemirror");
var analytics_1 = require("../../analytics");
var utils_1 = require("../utils");
function createInputRule(regexp, nodeType) {
return prosemirror_1.wrappingInputRule(regexp, nodeType, {}, function (_, node) { return node.type === nodeType; });
}
exports.createInputRule = createInputRule;
function inputRulePlugin(schema) {
var rules = [];
if (schema.nodes.bulletList) {
// NOTE: we decided to restrict the creation of bullet lists to only "*"x
var rule = utils_1.defaultInputRuleHandler(createInputRule(/^\s*([\*\-]) $/, schema.nodes.bulletList));
rule.handler = analytics_1.trackAndInvoke('atlassian.editor.format.list.bullet.autoformatting', rule.handler);
rules.push(rule);
}
if (schema.nodes.orderedList) {
// NOTE: There is a built in input rule for ordered lists in ProseMirror. However, that
// input rule will allow for a list to start at any given number, which isn't allowed in
// markdown (where a ordered list will always start on 1). This is a slightly modified
// version of that input rule.
var rule = utils_1.defaultInputRuleHandler(createInputRule(/^(\d+)[\.\)] $/, schema.nodes.orderedList));
rule.handler = analytics_1.trackAndInvoke('atlassian.editor.format.list.numbered.autoformatting', rule.handler);
rules.push(rule);
}
if (rules.length !== 0) {
return prosemirror_1.inputRules({ rules: rules });
}
}
exports.default = inputRulePlugin;
//# sourceMappingURL=input-rule.js.map