UNPKG

@atlaskit/editor-wikimarkup-transformer

Version:

Wiki markup transformer for JIRA and Confluence

32 lines (31 loc) 1.14 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.escapeHandler = escapeHandler; /** * In Jira, following characters are escaped * private static final Pattern ESCAPING_PATTERN = Pattern.compile("(^|(?<!\\\\))\\\\([\\-\\#\\*\\_\\+\\?\\^\\~\\|\\%\\{\\}\\[\\]\\(\\)\\!\\@])"); * https://stash.atlassian.com/projects/JIRACLOUD/repos/jira/browse/jira-components/jira-renderer/src/main/java/com/atlassian/renderer/v2/components/BackslashEscapeRendererComponent.java */ var escapedChar = ['-', '#', '*', '_', '+', '?', '^', '~', '|', '%', '{', '}', '[', ']', '(', ')', '!', '@']; function escapeHandler(input, position) { var buffer = []; var char = input.charAt(position); var prevChar = input.charAt(position - 1); var nextChar = input.charAt(position + 1); /** * Ported from Jira: * If previous char is also a backslash, then this is not a valid escape */ if (escapedChar.indexOf(nextChar) === -1 || prevChar === '\\') { // Insert \ in buffer mode buffer.push(char); } buffer.push(nextChar); return { type: 'text', text: buffer.join(''), length: 2 }; }