@atlaskit/editor-wikimarkup-transformer
Version:
Wiki markup transformer for JIRA and Confluence
41 lines (39 loc) • 1.08 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.forceLineBreak = void 0;
/**
* 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*\\)/;
var forceLineBreak = exports.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
};
}