UNPKG

@atlaskit/editor-wikimarkup-transformer

Version:

Wiki markup transformer for JIRA and Confluence

36 lines (35 loc) 887 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 const FORCE_LINE_BREAK_REGEX = /^\\{2}(?!\S*\\)/; export const forceLineBreak = ({ input, position, schema }) => { if (position > 0) { const charBefore = input.charAt(position - 1); if (charBefore === '\\') { return fallback(input, position); } } const 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 }; }