UNPKG

@atlaskit/editor-wikimarkup-transformer

Version:

Wiki markup transformer for JIRA and Confluence

35 lines (34 loc) 952 B
/** * Jira is using the following regex to match force line break * private static final Pattern FORCE_NEWLINE = Pattern.compile("(?<!\\\\)\\\\{2}(?!\\S*\\\\)"); */ // Ignored via go/ees005 // eslint-disable-next-line require-unicode-regexp var FORCE_LINE_BREAK_REGEX = /^\\{2}(?!\S*\\)/; export var forceLineBreak = function forceLineBreak(_ref) { var input = _ref.input, position = _ref.position, schema = _ref.schema; if (position > 0) { var charBefore = input.charAt(position - 1); if (charBefore === '\\') { return fallback(input, position); } } var match = input.substring(position).match(FORCE_LINE_BREAK_REGEX); if (match) { return { type: 'pmnode', nodes: [schema.nodes.hardBreak.createChecked()], length: 2 }; } return fallback(input, position); }; function fallback(input, position) { return { type: 'text', text: input.substr(position, 2), length: 2 }; }