@atlaskit/editor-wikimarkup-transformer
Version:
Wiki markup transformer for JIRA and Confluence
51 lines • 1.46 kB
JavaScript
import { TokenType } from './';
import { hasAnyOfMarks, getSurroundingSymbols } from '../utils/text';
import { commonFormatter } from './common-formatter';
import { parseString } from '../text';
export const superscript = ({
input,
position,
schema,
context
}) => {
/**
* The following token types will be ignored in parsing
* the content of a mark
*/
const ignoreTokenTypes = [TokenType.DOUBLE_DASH_SYMBOL, TokenType.TRIPLE_DASH_SYMBOL, TokenType.QUADRUPLE_DASH_SYMBOL, TokenType.ISSUE_KEY, TokenType.TABLE];
// Adding subsup mark to all text
const contentDecorator = n => {
const mark = schema.marks.subsup.create({
type: 'sup'
});
// We don't want to mix `code` mark with others
if (n.type.name === 'text' && !hasAnyOfMarks(n, ['subsup', 'code'])) {
return n.mark([...n.marks, mark]);
}
return n;
};
const rawContentProcessor = (raw, length) => {
const content = parseString({
schema,
context,
ignoreTokenTypes: ignoreTokenTypes,
input: raw
});
const decoratedContent = content.map(contentDecorator);
return {
type: 'pmnode',
nodes: decoratedContent,
length
};
};
const {
openingSymbol,
closingSymbol
} = getSurroundingSymbols(input.substring(position), '^', '^');
return commonFormatter(input, position, schema, {
opening: openingSymbol,
closing: closingSymbol,
context,
rawContentProcessor
});
};