UNPKG

fastcomments-react-native-sdk

Version:

React Native FastComments Components. Add live commenting to any React Native application.

80 lines (79 loc) 2.62 kB
import { defaultTokenizer, toTextTrimmed } from "../editor-node-transform"; import { EditorNodeType } from "../node-types"; const SupportedNodes = { // text is implicit '\n': { start: '\n', type: EditorNodeType.NEWLINE, lookaheadIgnore: null }, // TODO this is the fastcomments format. replace with standard markdown and allow this to be customizable before launching standalone WYSIWYG library. '[img]': { start: '[img]', end: '[/img]', type: EditorNodeType.IMAGE, lookaheadIgnore: null, }, '**': { start: '**', end: '**', type: EditorNodeType.TEXT_BOLD, lookaheadIgnore: null, }, '*': { start: '*', end: '*', type: EditorNodeType.TEXT_ITALIC, lookaheadIgnore: null, }, '~~': { start: '~~', end: '~~', type: EditorNodeType.TEXT_STRIKETHROUGH, lookaheadIgnore: null, }, '<u>': { start: '<u>', end: '</u>', type: EditorNodeType.TEXT_UNDERLINE, lookaheadIgnore: null, }, }; export const EditorFormatConfigurationMarkdown = { tokenize: (input) => defaultTokenizer(input, SupportedNodes), formatters: { [EditorNodeType.NEWLINE]: (_node, _trimToLength) => { return '\n'; }, [EditorNodeType.TEXT]: (node, trimToLength) => { return toTextTrimmed(node, null, null, trimToLength); }, [EditorNodeType.TEXT_BOLD]: (node, trimToLength) => { return toTextTrimmed(node, '**', '**', trimToLength); }, [EditorNodeType.EMOTICON]: (node, _trimToLength) => { if (!('content' in node)) { return ''; } // images should not be trimmed return `![](${node.content})`; }, [EditorNodeType.IMAGE]: (node, _trimToLength) => { if (!('content' in node)) { return ''; } // images should not be trimmed return `![](${node.content})`; }, [EditorNodeType.TEXT_ITALIC]: (node, trimToLength) => { return toTextTrimmed(node, '*', '*', trimToLength); }, [EditorNodeType.TEXT_STRIKETHROUGH]: (node, trimToLength) => { return toTextTrimmed(node, '~~', '~~', trimToLength); }, [EditorNodeType.TEXT_UNDERLINE]: (node, trimToLength) => { // if you don't support underline then disable it in the toolbar. return toTextTrimmed(node, '<u>', '</u>', trimToLength); }, } };