@atlaskit/editor-core
Version:
A package contains Atlassian editor core functionality
28 lines • 1.49 kB
JavaScript
import { inputRules, wrappingInputRule } from '../../prosemirror';
import { trackAndInvoke } from '../../analytics';
import { defaultInputRuleHandler } from '../utils';
export function createInputRule(regexp, nodeType) {
return wrappingInputRule(regexp, nodeType, {}, function (_, node) { return node.type === nodeType; });
}
export default function inputRulePlugin(schema) {
var rules = [];
if (schema.nodes.bulletList) {
// NOTE: we decided to restrict the creation of bullet lists to only "*"x
var rule = defaultInputRuleHandler(createInputRule(/^\s*([\*\-]) $/, schema.nodes.bulletList));
rule.handler = 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 = defaultInputRuleHandler(createInputRule(/^(\d+)[\.\)] $/, schema.nodes.orderedList));
rule.handler = trackAndInvoke('atlassian.editor.format.list.numbered.autoformatting', rule.handler);
rules.push(rule);
}
if (rules.length !== 0) {
return inputRules({ rules: rules });
}
}
//# sourceMappingURL=input-rule.js.map